1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-03 16:10:26 +00:00

update search user

user can search if he/she has no permission of using global address book
This commit is contained in:
lian
2017-02-13 16:03:31 +08:00
parent 7736ff0893
commit c904884526
2 changed files with 143 additions and 69 deletions

View File

@@ -4,8 +4,10 @@ from mock import patch
from django.core.urlresolvers import reverse
from django.test import override_settings
from seahub.contacts.models import Contact
from seahub.profile.models import Profile
from seahub.profile.utils import refresh_cache
from seahub.api2.endpoints.search_user import SearchUser
from seahub.test_utils import BaseTestCase
class SearchUserTest(BaseTestCase):
@@ -154,3 +156,30 @@ class SearchUserTest(BaseTestCase):
self.assertEqual(200, resp.status_code)
assert json_resp['users'][0]['email'] == self.admin.username
@patch.object(SearchUser, '_can_use_global_address_book')
def test_search_with_not_use_global_address_book(self, mock_can_use_global_address_book):
mock_can_use_global_address_book.return_value = False
resp = self.client.get(self.endpoint + '?q=%s' % self.admin.username)
json_resp = json.loads(resp.content)
self.assertEqual(200, resp.status_code)
assert json_resp['users'][0]['email'] == self.admin.username
@patch.object(SearchUser, '_can_use_global_address_book')
def test_search_by_contact_with_not_use_global_address_book(self, mock_can_use_global_address_book):
mock_can_use_global_address_book.return_value = False
Contact.objects.add_contact(self.user.username, self.admin.username)
nickname_of_admin = 'nickname of admin'
Profile.objects.add_or_update(self.admin.username,
nickname=nickname_of_admin)
resp = self.client.get(self.endpoint + '?q=%s' % nickname_of_admin)
json_resp = json.loads(resp.content)
self.assertEqual(200, resp.status_code)
assert json_resp['users'][0]['email'] == self.admin.username