tests: Added ZulipTestCase.example_user() function.

The example_user() function is specifically designed for
AARON, hamlet, cordelia, and friends, and it allows a concise
way of using their built-in user profiles. Eventually, the
widespread use of example_user() should help us with refactorings
such as moving the tests users out of the "zulip.com" realm
and deprecating get_user_profile_by_email.
This commit is contained in:
Steve Howell
2017-05-07 08:21:26 -07:00
committed by Tim Abbott
parent a44a291cdf
commit 942db9b6c5
24 changed files with 219 additions and 204 deletions

View File

@@ -207,6 +207,21 @@ class ZulipTestCase(TestCase):
django_client = self.client # see WRAPPER_COMMENT django_client = self.client # see WRAPPER_COMMENT
return django_client.get(url, info, **kwargs) return django_client.get(url, info, **kwargs)
example_user_map = dict(
hamlet='hamlet@zulip.com',
cordelia='cordelia@zulip.com',
iago='iago@zulip.com',
prospero='prospero@zulip.com',
othello='othello@zulip.com',
AARON='AARON@zulip.com',
ZOE='ZOE@zulip.com',
)
def example_user(self, name):
# type: (str) -> UserProfile
email = self.example_user_map[name]
return get_user_profile_by_email(email)
def login_with_return(self, email, password=None): def login_with_return(self, email, password=None):
# type: (Text, Optional[Text]) -> HttpResponse # type: (Text, Optional[Text]) -> HttpResponse
if password is None: if password is None:

View File

@@ -176,7 +176,7 @@ class AlertWordTests(ZulipTestCase):
def test_alert_flags(self): def test_alert_flags(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile_hamlet = get_user_profile_by_email("hamlet@zulip.com") user_profile_hamlet = self.example_user('hamlet')
result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])}) result = self.client_put('/json/users/me/alert_words', {'alert_words': ujson.dumps(['one', 'two', 'three'])})
self.assert_json_success(result) self.assert_json_success(result)

View File

@@ -16,7 +16,7 @@ from zerver.models import Attachment
class AttachmentsTests(ZulipTestCase): class AttachmentsTests(ZulipTestCase):
def setUp(self): def setUp(self):
# type: () -> None # type: () -> None
user = get_user_profile_by_email("cordelia@zulip.com") user = self.example_user('cordelia')
self.attachment = Attachment.objects.create( self.attachment = Attachment.objects.create(
file_name='test.txt', path_id='foo/bar/test.txt', owner=user) file_name='test.txt', path_id='foo/bar/test.txt', owner=user)
@@ -25,7 +25,7 @@ class AttachmentsTests(ZulipTestCase):
self.login("cordelia@zulip.com") self.login("cordelia@zulip.com")
result = self.client_get('/json/attachments') result = self.client_get('/json/attachments')
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email("cordelia@zulip.com") user = self.example_user('cordelia')
attachments = user_attachments(user) attachments = user_attachments(user)
data = ujson.loads(result.content) data = ujson.loads(result.content)
self.assertEqual(data['attachments'], attachments) self.assertEqual(data['attachments'], attachments)
@@ -36,7 +36,7 @@ class AttachmentsTests(ZulipTestCase):
self.login("cordelia@zulip.com") self.login("cordelia@zulip.com")
result = self.client_delete('/json/attachments/{pk}'.format(pk=self.attachment.pk)) result = self.client_delete('/json/attachments/{pk}'.format(pk=self.attachment.pk))
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email("cordelia@zulip.com") user = self.example_user('cordelia')
attachments = user_attachments(user) attachments = user_attachments(user)
self.assertEqual(attachments, []) self.assertEqual(attachments, [])
@@ -53,7 +53,7 @@ class AttachmentsTests(ZulipTestCase):
self.login("iago@zulip.com") self.login("iago@zulip.com")
result = self.client_delete('/json/attachments/{pk}'.format(pk=self.attachment.pk)) result = self.client_delete('/json/attachments/{pk}'.format(pk=self.attachment.pk))
self.assert_json_error(result, 'Invalid attachment') self.assert_json_error(result, 'Invalid attachment')
user = get_user_profile_by_email("cordelia@zulip.com") user = self.example_user('cordelia')
attachments = user_attachments(user) attachments = user_attachments(user)
self.assertEqual(attachments, [self.attachment.to_dict()]) self.assertEqual(attachments, [self.attachment.to_dict()])

View File

@@ -32,7 +32,7 @@ class TestRealmAuditLog(ZulipTestCase):
def test_change_password(self): def test_change_password(self):
# type: () -> None # type: () -> None
now = timezone_now() now = timezone_now()
user = get_user_profile_by_email("hamlet@zulip.com") user = self.example_user('hamlet')
password = 'test1' password = 'test1'
do_change_password(user, password) do_change_password(user, password)
self.assertEqual(RealmAuditLog.objects.filter(event_type='user_change_password', self.assertEqual(RealmAuditLog.objects.filter(event_type='user_change_password',
@@ -42,7 +42,7 @@ class TestRealmAuditLog(ZulipTestCase):
def test_change_email(self): def test_change_email(self):
# type: () -> None # type: () -> None
now = timezone_now() now = timezone_now()
user = get_user_profile_by_email("hamlet@zulip.com") user = self.example_user('hamlet')
email = 'test@example.com' email = 'test@example.com'
do_change_user_email(user, email) do_change_user_email(user, email)
self.assertEqual(RealmAuditLog.objects.filter(event_type='user_email_changed', self.assertEqual(RealmAuditLog.objects.filter(event_type='user_email_changed',
@@ -52,7 +52,7 @@ class TestRealmAuditLog(ZulipTestCase):
def test_change_avatar_source(self): def test_change_avatar_source(self):
# type: () -> None # type: () -> None
now = timezone_now() now = timezone_now()
user = get_user_profile_by_email("hamlet@zulip.com") user = self.example_user('hamlet')
avatar_source = u'G' avatar_source = u'G'
do_change_avatar_fields(user, avatar_source) do_change_avatar_fields(user, avatar_source)
self.assertEqual(RealmAuditLog.objects.filter(event_type='user_change_avatar_source', self.assertEqual(RealmAuditLog.objects.filter(event_type='user_change_avatar_source',
@@ -62,9 +62,9 @@ class TestRealmAuditLog(ZulipTestCase):
def test_change_bot_owner(self): def test_change_bot_owner(self):
# type: () -> None # type: () -> None
now = timezone_now() now = timezone_now()
admin = get_user_profile_by_email('iago@zulip.com') admin = self.example_user('iago')
bot = get_user_profile_by_email("notification-bot@zulip.com") bot = get_user_profile_by_email("notification-bot@zulip.com")
bot_owner = get_user_profile_by_email("hamlet@zulip.com") bot_owner = self.example_user('hamlet')
do_change_bot_owner(bot, bot_owner, admin) do_change_bot_owner(bot, bot_owner, admin)
self.assertEqual(RealmAuditLog.objects.filter(event_type='bot_owner_changed', self.assertEqual(RealmAuditLog.objects.filter(event_type='bot_owner_changed',
event_time__gte=now).count(), 1) event_time__gte=now).count(), 1)
@@ -73,7 +73,7 @@ class TestRealmAuditLog(ZulipTestCase):
def test_regenerate_api_key(self): def test_regenerate_api_key(self):
# type: () -> None # type: () -> None
now = timezone_now() now = timezone_now()
user = get_user_profile_by_email("hamlet@zulip.com") user = self.example_user('hamlet')
do_regenerate_api_key(user, user) do_regenerate_api_key(user, user)
self.assertEqual(RealmAuditLog.objects.filter(event_type='user_api_key_changed', self.assertEqual(RealmAuditLog.objects.filter(event_type='user_api_key_changed',
event_time__gte=now).count(), 1) event_time__gte=now).count(), 1)

View File

@@ -781,7 +781,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
self.assertEqual(query_params["realm"], ['http://zulip.testserver']) self.assertEqual(query_params["realm"], ['http://zulip.testserver'])
self.assertEqual(query_params["email"], ['hamlet@zulip.com']) self.assertEqual(query_params["email"], ['hamlet@zulip.com'])
encrypted_api_key = query_params["otp_encrypted_api_key"][0] encrypted_api_key = query_params["otp_encrypted_api_key"][0]
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").api_key, self.assertEqual(self.example_user('hamlet').api_key,
otp_decrypt_api_key(encrypted_api_key, mobile_flow_otp)) otp_decrypt_api_key(encrypted_api_key, mobile_flow_otp))
def test_log_into_subdomain(self): def test_log_into_subdomain(self):
@@ -794,7 +794,7 @@ class GoogleSubdomainLoginTest(GoogleOAuthTest):
with mock.patch('zerver.views.auth.get_subdomain', return_value='zulip'): with mock.patch('zerver.views.auth.get_subdomain', return_value='zulip'):
result = self.client_get('/accounts/login/subdomain/') result = self.client_get('/accounts/login/subdomain/')
self.assertEqual(result.status_code, 302) self.assertEqual(result.status_code, 302)
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
# If authenticate_remote_user detects a subdomain mismatch, then # If authenticate_remote_user detects a subdomain mismatch, then
@@ -910,7 +910,7 @@ class GoogleLoginTest(GoogleOAuthTest):
account_response = ResponseMock(200, account_data) account_response = ResponseMock(200, account_data)
self.google_oauth2_test(token_response, account_response) self.google_oauth2_test(token_response, account_response)
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
def test_google_oauth2_registration(self): def test_google_oauth2_registration(self):
@@ -1001,7 +1001,7 @@ class GoogleLoginTest(GoogleOAuthTest):
account_response = ResponseMock(200, account_data) account_response = ResponseMock(200, account_data)
self.google_oauth2_test(token_response, account_response) self.google_oauth2_test(token_response, account_response)
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
def test_google_oauth2_account_response_no_email(self): def test_google_oauth2_account_response_no_email(self):

View File

@@ -224,7 +224,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_add_bot_with_default_sending_stream_private_allowed(self): def test_add_bot_with_default_sending_stream_private_allowed(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
self.subscribe_to_stream(user_profile.email, stream.name) self.subscribe_to_stream(user_profile.email, stream.name)
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -262,7 +262,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_add_bot_with_default_sending_stream_private_denied(self): def test_add_bot_with_default_sending_stream_private_denied(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark") self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark")
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -289,7 +289,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_add_bot_with_default_events_register_stream_private_allowed(self): def test_add_bot_with_default_events_register_stream_private_allowed(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = self.subscribe_to_stream(user_profile.email, 'Denmark') stream = self.subscribe_to_stream(user_profile.email, 'Denmark')
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -326,7 +326,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_add_bot_with_default_events_register_stream_private_denied(self): def test_add_bot_with_default_events_register_stream_private_denied(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark") self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark")
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -597,7 +597,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_patch_bot_to_stream_private_allowed(self): def test_patch_bot_to_stream_private_allowed(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = self.subscribe_to_stream(user_profile.email, "Denmark") stream = self.subscribe_to_stream(user_profile.email, "Denmark")
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -623,7 +623,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_patch_bot_to_stream_private_denied(self): def test_patch_bot_to_stream_private_denied(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark") self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark")
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -680,7 +680,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_patch_bot_events_register_stream_allowed(self): def test_patch_bot_events_register_stream_allowed(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = self.subscribe_to_stream(user_profile.email, "Denmark") stream = self.subscribe_to_stream(user_profile.email, "Denmark")
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)
@@ -705,7 +705,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
def test_patch_bot_events_register_stream_denied(self): def test_patch_bot_events_register_stream_denied(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark") self.unsubscribe_from_stream("hamlet@zulip.com", "Denmark")
do_change_stream_invite_only(stream, True) do_change_stream_invite_only(stream, True)

View File

@@ -163,7 +163,7 @@ def bugdown_convert(text):
# type: (Text) -> Text # type: (Text) -> Text
return bugdown.convert(text, message_realm=get_realm('zulip')) return bugdown.convert(text, message_realm=get_realm('zulip'))
class BugdownTest(TestCase): class BugdownTest(ZulipTestCase):
def load_bugdown_tests(self): def load_bugdown_tests(self):
# type: () -> Tuple[Dict[Text, Any], List[List[Text]]] # type: () -> Tuple[Dict[Text, Any], List[List[Text]]]
test_fixtures = {} test_fixtures = {}
@@ -236,7 +236,7 @@ class BugdownTest(TestCase):
without_preview = '<p><a href="http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg" target="_blank" title="http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg">http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg</a></p>' without_preview = '<p><a href="http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg" target="_blank" title="http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg">http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg</a></p>'
content = 'http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg' content = 'http://cdn.wallpapersafari.com/13/6/16eVjx.jpeg'
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
converted = render_markdown(msg, content) converted = render_markdown(msg, content)
self.assertEqual(converted, with_preview) self.assertEqual(converted, with_preview)
@@ -245,7 +245,7 @@ class BugdownTest(TestCase):
setattr(realm, 'inline_image_preview', False) setattr(realm, 'inline_image_preview', False)
realm.save() realm.save()
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
converted = render_markdown(msg, content) converted = render_markdown(msg, content)
self.assertEqual(converted, without_preview) self.assertEqual(converted, without_preview)
@@ -256,7 +256,7 @@ class BugdownTest(TestCase):
content = 'http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg\nhttp://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg\nhttp://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg' content = 'http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg\nhttp://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg\nhttp://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg'
expected = '<p><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg">http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg</a><br>\n<a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg">http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg</a><br>\n<a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg">http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg</a></p>\n<div class="message_inline_image"><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg"><img src="https://external-content.zulipcdn.net/1081f3eb3d307ff5b578c1f5ce9d4cef8f8953c4/687474703a2f2f696d6167696e672e6e696b6f6e2e636f6d2f6c696e6575702f64736c722f64662f696d672f73616d706c652f696d675f30312e6a7067"></a></div><div class="message_inline_image"><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg"><img src="https://external-content.zulipcdn.net/8a2da7577389c522fab18ba2e6d6947b85458074/687474703a2f2f696d6167696e672e6e696b6f6e2e636f6d2f6c696e6575702f64736c722f64662f696d672f73616d706c652f696d675f30322e6a7067"></a></div><div class="message_inline_image"><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg"><img src="https://external-content.zulipcdn.net/9c389273b239846aa6e07e109216773934e52828/687474703a2f2f696d6167696e672e6e696b6f6e2e636f6d2f6c696e6575702f64736c722f64662f696d672f73616d706c652f696d675f30332e6a7067"></a></div>' expected = '<p><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg">http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg</a><br>\n<a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg">http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg</a><br>\n<a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg">http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg</a></p>\n<div class="message_inline_image"><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_01.jpg"><img src="https://external-content.zulipcdn.net/1081f3eb3d307ff5b578c1f5ce9d4cef8f8953c4/687474703a2f2f696d6167696e672e6e696b6f6e2e636f6d2f6c696e6575702f64736c722f64662f696d672f73616d706c652f696d675f30312e6a7067"></a></div><div class="message_inline_image"><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_02.jpg"><img src="https://external-content.zulipcdn.net/8a2da7577389c522fab18ba2e6d6947b85458074/687474703a2f2f696d6167696e672e6e696b6f6e2e636f6d2f6c696e6575702f64736c722f64662f696d672f73616d706c652f696d675f30322e6a7067"></a></div><div class="message_inline_image"><a href="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg" target="_blank" title="http://imaging.nikon.com/lineup/dslr/df/img/sample/img_03.jpg"><img src="https://external-content.zulipcdn.net/9c389273b239846aa6e07e109216773934e52828/687474703a2f2f696d6167696e672e6e696b6f6e2e636f6d2f6c696e6575702f64736c722f64662f696d672f73616d706c652f696d675f30332e6a7067"></a></div>'
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
converted = render_markdown(msg, content) converted = render_markdown(msg, content)
self.assertEqual(converted, expected) self.assertEqual(converted, expected)
@@ -276,7 +276,7 @@ class BugdownTest(TestCase):
settings.INLINE_IMAGE_PREVIEW = True settings.INLINE_IMAGE_PREVIEW = True
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
bugdown.current_message = copy.deepcopy(Message(sender=sender_user_profile, sending_client=get_client("test"))) bugdown.current_message = copy.deepcopy(Message(sender=sender_user_profile, sending_client=get_client("test")))
realm = bugdown.current_message.get_realm() realm = bugdown.current_message.get_realm()
@@ -290,7 +290,7 @@ class BugdownTest(TestCase):
@override_settings(INLINE_URL_EMBED_PREVIEW=False) @override_settings(INLINE_URL_EMBED_PREVIEW=False)
def test_url_embed_preview_enabled_for_realm(self): def test_url_embed_preview_enabled_for_realm(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
message = copy.deepcopy(Message(sender=sender_user_profile, sending_client=get_client("test"))) message = copy.deepcopy(Message(sender=sender_user_profile, sending_client=get_client("test")))
realm = message.get_realm() realm = message.get_realm()
@@ -488,7 +488,7 @@ class BugdownTest(TestCase):
check_add_realm_emoji(realm, "test", 'test.png') check_add_realm_emoji(realm, "test", 'test.png')
# Needs to mock an actual message because that's how bugdown obtains the realm # Needs to mock an actual message because that's how bugdown obtains the realm
msg = Message(sender=get_user_profile_by_email("hamlet@zulip.com")) msg = Message(sender=self.example_user('hamlet'))
converted = bugdown.convert(":test:", message_realm=realm, message=msg) converted = bugdown.convert(":test:", message_realm=realm, message=msg)
self.assertEqual(converted, '<p>%s</p>' % (emoji_img(':test:', 'test.png', realm.id))) self.assertEqual(converted, '<p>%s</p>' % (emoji_img(':test:', 'test.png', realm.id)))
@@ -519,7 +519,7 @@ class BugdownTest(TestCase):
'<RealmFilter(zulip): #(?P<id>[0-9]{2,8})' '<RealmFilter(zulip): #(?P<id>[0-9]{2,8})'
' https://trac.zulip.net/ticket/%(id)s>') ' https://trac.zulip.net/ticket/%(id)s>')
msg = Message(sender=get_user_profile_by_email("othello@zulip.com"), msg = Message(sender=self.example_user('othello'),
subject="#444") subject="#444")
flush_per_request_caches() flush_per_request_caches()
@@ -533,7 +533,7 @@ class BugdownTest(TestCase):
RealmFilter(realm=realm, pattern=r'#(?P<id>[a-zA-Z]+-[0-9]+)', RealmFilter(realm=realm, pattern=r'#(?P<id>[a-zA-Z]+-[0-9]+)',
url_format_string=r'https://trac.zulip.net/ticket/%(id)s').save() url_format_string=r'https://trac.zulip.net/ticket/%(id)s').save()
msg = Message(sender=get_user_profile_by_email('hamlet@zulip.com')) msg = Message(sender=self.example_user('hamlet'))
content = '#ZUL-123 was fixed and code was deployed to production, also #zul-321 was deployed to staging' content = '#ZUL-123 was fixed and code was deployed to production, also #zul-321 was deployed to staging'
converted = bugdown.convert(content, message_realm=realm, message=msg) converted = bugdown.convert(content, message_realm=realm, message=msg)
@@ -602,14 +602,14 @@ class BugdownTest(TestCase):
realm = get_realm('zulip') realm = get_realm('zulip')
RealmFilter(realm=realm, pattern=r"#(?P<id>[0-9]{2,8})", RealmFilter(realm=realm, pattern=r"#(?P<id>[0-9]{2,8})",
url_format_string=r"https://trac.zulip.net/ticket/%(id)s").save() url_format_string=r"https://trac.zulip.net/ticket/%(id)s").save()
boring_msg = Message(sender=get_user_profile_by_email("othello@zulip.com"), boring_msg = Message(sender=self.example_user('othello'),
subject=u"no match here") subject=u"no match here")
converted_boring_subject = bugdown.subject_links(realm.id, boring_msg.subject) converted_boring_subject = bugdown.subject_links(realm.id, boring_msg.subject)
self.assertEqual(converted_boring_subject, []) self.assertEqual(converted_boring_subject, [])
def test_is_status_message(self): def test_is_status_message(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
msg = Message(sender=user_profile, sending_client=get_client("test")) msg = Message(sender=user_profile, sending_client=get_client("test"))
content = '/me makes a list\n* one\n* two' content = '/me makes a list\n* one\n* two'
@@ -630,7 +630,7 @@ class BugdownTest(TestCase):
def test_alert_words(self): def test_alert_words(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
do_set_alert_words(user_profile, ["ALERTWORD", "scaryword"]) do_set_alert_words(user_profile, ["ALERTWORD", "scaryword"])
msg = Message(sender=user_profile, sending_client=get_client("test")) msg = Message(sender=user_profile, sending_client=get_client("test"))
realm_alert_words = alert_words_in_realm(user_profile.realm) realm_alert_words = alert_words_in_realm(user_profile.realm)
@@ -653,7 +653,7 @@ class BugdownTest(TestCase):
def test_mention_wildcard(self): def test_mention_wildcard(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
msg = Message(sender=user_profile, sending_client=get_client("test")) msg = Message(sender=user_profile, sending_client=get_client("test"))
content = "@all test" content = "@all test"
@@ -665,7 +665,7 @@ class BugdownTest(TestCase):
def test_mention_everyone(self): def test_mention_everyone(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
msg = Message(sender=user_profile, sending_client=get_client("test")) msg = Message(sender=user_profile, sending_client=get_client("test"))
content = "@everyone test" content = "@everyone test"
@@ -675,8 +675,8 @@ class BugdownTest(TestCase):
def test_mention_single(self): def test_mention_single(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
user_id = user_profile.id user_id = user_profile.id
@@ -690,8 +690,8 @@ class BugdownTest(TestCase):
def test_mention_shortname(self): def test_mention_shortname(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
user_id = user_profile.id user_id = user_profile.id
@@ -704,9 +704,9 @@ class BugdownTest(TestCase):
def test_mention_multiple(self): def test_mention_multiple(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
hamlet = get_user_profile_by_email("hamlet@zulip.com") hamlet = self.example_user('hamlet')
cordelia = get_user_profile_by_email("cordelia@zulip.com") cordelia = self.example_user('cordelia')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "@**King Hamlet** and @**cordelia**, check this out" content = "@**King Hamlet** and @**cordelia**, check this out"
@@ -723,7 +723,7 @@ class BugdownTest(TestCase):
def test_mention_invalid(self): def test_mention_invalid(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "Hey @**Nonexistent User**" content = "Hey @**Nonexistent User**"
@@ -734,7 +734,7 @@ class BugdownTest(TestCase):
def test_stream_single(self): def test_stream_single(self):
# type: () -> None # type: () -> None
denmark = get_stream('Denmark', get_realm('zulip')) denmark = get_stream('Denmark', get_realm('zulip'))
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "#**Denmark**" content = "#**Denmark**"
self.assertEqual( self.assertEqual(
@@ -745,7 +745,7 @@ class BugdownTest(TestCase):
def test_stream_multiple(self): def test_stream_multiple(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
realm = get_realm('zulip') realm = get_realm('zulip')
denmark = get_stream('Denmark', realm) denmark = get_stream('Denmark', realm)
@@ -765,7 +765,7 @@ class BugdownTest(TestCase):
# type: () -> None # type: () -> None
realm = get_realm('zulip') realm = get_realm('zulip')
case_sens = Stream.objects.create(name='CaseSens', realm=realm) case_sens = Stream.objects.create(name='CaseSens', realm=realm)
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "#**CaseSens**" content = "#**CaseSens**"
self.assertEqual( self.assertEqual(
@@ -781,7 +781,7 @@ class BugdownTest(TestCase):
test.""" test."""
realm = get_realm('zulip') realm = get_realm('zulip')
Stream.objects.create(name='CaseSens', realm=realm) Stream.objects.create(name='CaseSens', realm=realm)
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "#**casesens**" content = "#**casesens**"
self.assertEqual( self.assertEqual(
@@ -792,7 +792,7 @@ class BugdownTest(TestCase):
# type: () -> None # type: () -> None
realm = get_realm('zulip') realm = get_realm('zulip')
uni = Stream.objects.create(name=u'привет', realm=realm) uni = Stream.objects.create(name=u'привет', realm=realm)
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = u"#**привет**" content = u"#**привет**"
self.assertEqual( self.assertEqual(
@@ -804,7 +804,7 @@ class BugdownTest(TestCase):
def test_stream_invalid(self): def test_stream_invalid(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
msg = Message(sender=sender_user_profile, sending_client=get_client("test")) msg = Message(sender=sender_user_profile, sending_client=get_client("test"))
content = "There #**Nonexistentstream**" content = "There #**Nonexistentstream**"
@@ -948,7 +948,7 @@ class BugdownApiTests(ZulipTestCase):
) )
self.assert_json_success(result) self.assert_json_success(result)
data = ujson.loads(result.content) data = ujson.loads(result.content)
user_id = get_user_profile_by_email('hamlet@zulip.com').id user_id = self.example_user('hamlet').id
self.assertEqual(data['rendered'], self.assertEqual(data['rendered'],
u'<p>This mentions <a class="stream" data-stream-id="%s" href="/#narrow/stream/Denmark">#Denmark</a> and <span class="user-mention" data-user-email="%s" data-user-id="%s">@King Hamlet</span>.</p>' % (get_stream("Denmark", get_realm("zulip")).id, 'hamlet@zulip.com', user_id)) u'<p>This mentions <a class="stream" data-stream-id="%s" href="/#narrow/stream/Denmark">#Denmark</a> and <span class="user-mention" data-user-email="%s" data-user-id="%s">@King Hamlet</span>.</p>' % (get_stream("Denmark", get_realm("zulip")).id, 'hamlet@zulip.com', user_id))
@@ -973,10 +973,10 @@ class BugdownErrorTests(ZulipTestCase):
class BugdownAvatarTestCase(ZulipTestCase): class BugdownAvatarTestCase(ZulipTestCase):
def test_avatar_with_id(self): def test_avatar_with_id(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
message = Message(sender=sender_user_profile, sending_client=get_client("test")) message = Message(sender=sender_user_profile, sending_client=get_client("test"))
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
msg = '!avatar({0})'.format(user_profile.email) msg = '!avatar({0})'.format(user_profile.email)
converted = bugdown.convert(msg, message=message) converted = bugdown.convert(msg, message=message)
values = {'email': user_profile.email, 'id': user_profile.id} values = {'email': user_profile.email, 'id': user_profile.id}
@@ -986,7 +986,7 @@ class BugdownAvatarTestCase(ZulipTestCase):
def test_avatar_of_unregistered_user(self): def test_avatar_of_unregistered_user(self):
# type: () -> None # type: () -> None
sender_user_profile = get_user_profile_by_email("othello@zulip.com") sender_user_profile = self.example_user('othello')
message = Message(sender=sender_user_profile, sending_client=get_client("test")) message = Message(sender=sender_user_profile, sending_client=get_client("test"))
email = 'fakeuser@example.com' email = 'fakeuser@example.com'

View File

@@ -248,7 +248,7 @@ class CustomProfileDataTest(ZulipTestCase):
def test_delete(self): def test_delete(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email('iago@zulip.com') user_profile = self.example_user('iago')
realm = user_profile.realm realm = user_profile.realm
field = try_add_realm_custom_profile_field( field = try_add_realm_custom_profile_field(
realm, realm,

View File

@@ -102,7 +102,7 @@ class EmailChangeTestCase(ZulipTestCase):
def test_start_email_change_process(self): def test_start_email_change_process(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
do_start_email_change_process(user_profile, 'hamlet-new@zulip.com') do_start_email_change_process(user_profile, 'hamlet-new@zulip.com')
self.assertEqual(EmailChangeStatus.objects.count(), 1) self.assertEqual(EmailChangeStatus.objects.count(), 1)

View File

@@ -87,7 +87,7 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase):
# build dummy messages for stream # build dummy messages for stream
# test valid incoming stream message is processed properly # test valid incoming stream message is processed properly
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
@@ -116,7 +116,7 @@ class TestStreamEmailMessagesEmptyBody(ZulipTestCase):
# build dummy messages for stream # build dummy messages for stream
# test message with empty body is not sent # test message with empty body is not sent
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
@@ -161,7 +161,7 @@ class TestMissedPersonalMessageEmailMessages(ZulipTestCase):
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
usermessage = most_recent_usermessage(user_profile) usermessage = most_recent_usermessage(user_profile)
# we don't want to send actual emails but we do need to create and store the # we don't want to send actual emails but we do need to create and store the
@@ -179,11 +179,11 @@ class TestMissedPersonalMessageEmailMessages(ZulipTestCase):
# self.login("hamlet@zulip.com") # self.login("hamlet@zulip.com")
# confirm that Hamlet got the message # confirm that Hamlet got the message
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
message = most_recent_message(user_profile) message = most_recent_message(user_profile)
self.assertEqual(message.content, "TestMissedMessageEmailMessages Body") self.assertEqual(message.content, "TestMissedMessageEmailMessages Body")
self.assertEqual(message.sender, get_user_profile_by_email("othello@zulip.com")) self.assertEqual(message.sender, self.example_user('othello'))
self.assertEqual(message.recipient.id, user_profile.id) self.assertEqual(message.recipient.id, user_profile.id)
self.assertEqual(message.recipient.type, Recipient.PERSONAL) self.assertEqual(message.recipient.type, Recipient.PERSONAL)
@@ -202,7 +202,7 @@ class TestMissedHuddleMessageEmailMessages(ZulipTestCase):
"iago@zulip.com"])}) "iago@zulip.com"])})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = get_user_profile_by_email("cordelia@zulip.com") user_profile = self.example_user('cordelia')
usermessage = most_recent_usermessage(user_profile) usermessage = most_recent_usermessage(user_profile)
# we don't want to send actual emails but we do need to create and store the # we don't want to send actual emails but we do need to create and store the
@@ -219,19 +219,19 @@ class TestMissedHuddleMessageEmailMessages(ZulipTestCase):
process_message(incoming_valid_message) process_message(incoming_valid_message)
# Confirm Iago received the message. # Confirm Iago received the message.
user_profile = get_user_profile_by_email("iago@zulip.com") user_profile = self.example_user('iago')
message = most_recent_message(user_profile) message = most_recent_message(user_profile)
self.assertEqual(message.content, "TestMissedHuddleMessageEmailMessages Body") self.assertEqual(message.content, "TestMissedHuddleMessageEmailMessages Body")
self.assertEqual(message.sender, get_user_profile_by_email("cordelia@zulip.com")) self.assertEqual(message.sender, self.example_user('cordelia'))
self.assertEqual(message.recipient.type, Recipient.HUDDLE) self.assertEqual(message.recipient.type, Recipient.HUDDLE)
# Confirm Othello received the message. # Confirm Othello received the message.
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
message = most_recent_message(user_profile) message = most_recent_message(user_profile)
self.assertEqual(message.content, "TestMissedHuddleMessageEmailMessages Body") self.assertEqual(message.content, "TestMissedHuddleMessageEmailMessages Body")
self.assertEqual(message.sender, get_user_profile_by_email("cordelia@zulip.com")) self.assertEqual(message.sender, self.example_user('cordelia'))
self.assertEqual(message.recipient.type, Recipient.HUDDLE) self.assertEqual(message.recipient.type, Recipient.HUDDLE)
class TestMissedMessageAddressWithEmptyGateway(ZulipTestCase): class TestMissedMessageAddressWithEmptyGateway(ZulipTestCase):
@@ -245,7 +245,7 @@ class TestMissedMessageAddressWithEmptyGateway(ZulipTestCase):
"iago@zulip.com"])}) "iago@zulip.com"])})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = get_user_profile_by_email("cordelia@zulip.com") user_profile = self.example_user('cordelia')
usermessage = most_recent_usermessage(user_profile) usermessage = most_recent_usermessage(user_profile)
with self.settings(EMAIL_GATEWAY_PATTERN=''): with self.settings(EMAIL_GATEWAY_PATTERN=''):
mm_address = create_missed_message_address(user_profile, usermessage.message) mm_address = create_missed_message_address(user_profile, usermessage.message)
@@ -268,7 +268,7 @@ class TestDigestEmailMessages(ZulipTestCase):
"to": "othello@zulip.com"}) "to": "othello@zulip.com"})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = get_user_profile_by_email("othello@zulip.com") user_profile = self.example_user('othello')
cutoff = time.mktime(datetime.datetime(year=2016, month=1, day=1).timetuple()) cutoff = time.mktime(datetime.datetime(year=2016, month=1, day=1).timetuple())
handle_digest_email(user_profile.id, cutoff) handle_digest_email(user_profile.id, cutoff)
@@ -282,7 +282,7 @@ class TestReplyExtraction(ZulipTestCase):
# build dummy messages for stream # build dummy messages for stream
# test valid incoming stream message is processed properly # test valid incoming stream message is processed properly
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
@@ -313,7 +313,7 @@ class TestReplyExtraction(ZulipTestCase):
# build dummy messages for stream # build dummy messages for stream
# test valid incoming stream message is processed properly # test valid incoming stream message is processed properly
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
stream = get_stream("Denmark", user_profile.realm) stream = get_stream("Denmark", user_profile.realm)
@@ -420,7 +420,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
}) })
self.assert_json_success(result) self.assert_json_success(result)
user_profile = get_user_profile_by_email("cordelia@zulip.com") user_profile = self.example_user('cordelia')
user_message = most_recent_usermessage(user_profile) user_message = most_recent_usermessage(user_profile)
return create_missed_message_address(user_profile, user_message.message) return create_missed_message_address(user_profile, user_message.message)

View File

@@ -195,7 +195,7 @@ class EventsEndpointTest(ZulipTestCase):
event=dict( event=dict(
type='other' type='other'
), ),
users=[get_user_profile_by_email('hamlet@zulip.com').id], users=[self.example_user('hamlet').id],
), ),
), ),
) )
@@ -348,7 +348,7 @@ class GetEventsTest(ZulipTestCase):
self.assertEqual(events[0]["message"]["display_recipient"], "Denmark") self.assertEqual(events[0]["message"]["display_recipient"], "Denmark")
class EventsRegisterTest(ZulipTestCase): class EventsRegisterTest(ZulipTestCase):
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = get_user_profile_by_email('hamlet@zulip.com')
maxDiff = None # type: Optional[int] maxDiff = None # type: Optional[int]
def create_bot(self, email): def create_bot(self, email):
@@ -534,7 +534,7 @@ class EventsRegisterTest(ZulipTestCase):
]) ])
message = self.send_message("cordelia@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, "hello") message = self.send_message("cordelia@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, "hello")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
events = self.do_test( events = self.do_test(
lambda: do_update_message_flags(user_profile, 'add', 'starred', lambda: do_update_message_flags(user_profile, 'add', 'starred',
[message], False, None, None), [message], False, None, None),
@@ -1351,8 +1351,8 @@ class EventsRegisterTest(ZulipTestCase):
('owner_id', check_int), ('owner_id', check_int),
])), ])),
]) ])
self.user_profile = get_user_profile_by_email('iago@zulip.com') self.user_profile = self.example_user('iago')
owner = get_user_profile_by_email('hamlet@zulip.com') owner = self.example_user('hamlet')
bot = self.create_bot('test-bot@zulip.com') bot = self.create_bot('test-bot@zulip.com')
action = lambda: do_change_bot_owner(bot, owner, self.user_profile) action = lambda: do_change_bot_owner(bot, owner, self.user_profile)
events = self.do_test(action) events = self.do_test(action)
@@ -1561,7 +1561,7 @@ class EventsRegisterTest(ZulipTestCase):
# Now remove the first user, to test the normal unsubscribe flow # Now remove the first user, to test the normal unsubscribe flow
action = lambda: bulk_remove_subscriptions( action = lambda: bulk_remove_subscriptions(
[get_user_profile_by_email("othello@zulip.com")], [self.example_user('othello')],
[stream]) [stream])
events = self.do_test(action, events = self.do_test(action,
include_subscribers=include_subscribers, include_subscribers=include_subscribers,
@@ -1572,7 +1572,7 @@ class EventsRegisterTest(ZulipTestCase):
# Now remove the second user, to test the 'vacate' event flow # Now remove the second user, to test the 'vacate' event flow
action = lambda: bulk_remove_subscriptions( action = lambda: bulk_remove_subscriptions(
[get_user_profile_by_email("hamlet@zulip.com")], [self.example_user('hamlet')],
[stream]) [stream])
events = self.do_test(action, events = self.do_test(action,
include_subscribers=include_subscribers, include_subscribers=include_subscribers,
@@ -1596,7 +1596,7 @@ class EventsRegisterTest(ZulipTestCase):
# Subscribe to a totally new invite-only stream, so it's just Hamlet on it # Subscribe to a totally new invite-only stream, so it's just Hamlet on it
stream = self.make_stream("private", get_realm("zulip"), invite_only=True) stream = self.make_stream("private", get_realm("zulip"), invite_only=True)
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
action = lambda: bulk_add_subscriptions([stream], [user_profile]) action = lambda: bulk_add_subscriptions([stream], [user_profile])
events = self.do_test(action, include_subscribers=include_subscribers, events = self.do_test(action, include_subscribers=include_subscribers,
num_events=2) num_events=2)

View File

@@ -60,8 +60,8 @@ class QueryUtilTest(ZulipTestCase):
# type: () -> None # type: () -> None
self._create_messages() self._create_messages()
cordelia = get_user_profile_by_email('cordelia@zulip.com') cordelia = self.example_user('cordelia')
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
def get_queries(): def get_queries():
# type: () -> List[Any] # type: () -> List[Any]
@@ -177,7 +177,7 @@ class QueryUtilTest(ZulipTestCase):
self.assertEqual(actual_msg.sender_id, expected_msg.sender_id) self.assertEqual(actual_msg.sender_id, expected_msg.sender_id)
class ExportTest(TestCase): class ExportTest(ZulipTestCase):
def setUp(self): def setUp(self):
# type: () -> None # type: () -> None
@@ -289,8 +289,8 @@ class ExportTest(TestCase):
# TODO, extract get_set/find_by_id, so we can split this test up # TODO, extract get_set/find_by_id, so we can split this test up
# Now, restrict users # Now, restrict users
cordelia = get_user_profile_by_email('cordelia@zulip.com') cordelia = self.example_user('cordelia')
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
user_ids = set([cordelia.id, hamlet.id]) user_ids = set([cordelia.id, hamlet.id])
full_data = self._export_realm(realm, exportable_user_ids=user_ids) full_data = self._export_realm(realm, exportable_user_ids=user_ids)

View File

@@ -71,7 +71,7 @@ class TopicHistoryTest(ZulipTestCase):
def create_test_message(topic, read, starred=False): def create_test_message(topic, read, starred=False):
# type: (str, bool, bool) -> None # type: (str, bool, bool) -> None
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
message = Message.objects.create( message = Message.objects.create(
sender=hamlet, sender=hamlet,
recipient=recipient, recipient=recipient,
@@ -469,7 +469,7 @@ class StreamMessagesTest(ZulipTestCase):
def test_stream_message_dict(self): def test_stream_message_dict(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("iago@zulip.com") user_profile = self.example_user('iago')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
content="whatever", subject="my topic") content="whatever", subject="my topic")
@@ -483,7 +483,7 @@ class StreamMessagesTest(ZulipTestCase):
def test_stream_message_unicode(self): def test_stream_message_unicode(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("iago@zulip.com") user_profile = self.example_user('iago')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
content="whatever", subject="my topic") content="whatever", subject="my topic")
@@ -494,7 +494,7 @@ class StreamMessagesTest(ZulipTestCase):
def test_message_mentions(self): def test_message_mentions(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("iago@zulip.com") user_profile = self.example_user('iago')
self.subscribe_to_stream(user_profile.email, "Denmark") self.subscribe_to_stream(user_profile.email, "Denmark")
self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM, self.send_message("hamlet@zulip.com", "Denmark", Recipient.STREAM,
content="test @**Iago** rules") content="test @**Iago** rules")
@@ -560,8 +560,8 @@ class MessageDictTest(ZulipTestCase):
@slow('builds lots of messages') @slow('builds lots of messages')
def test_bulk_message_fetching(self): def test_bulk_message_fetching(self):
# type: () -> None # type: () -> None
sender = get_user_profile_by_email('othello@zulip.com') sender = self.example_user('othello')
receiver = get_user_profile_by_email('hamlet@zulip.com') receiver = self.example_user('hamlet')
pm_recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL) pm_recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
stream_name = u'Çiğdem' stream_name = u'Çiğdem'
stream = self.make_stream(stream_name) stream = self.make_stream(stream_name)
@@ -606,8 +606,8 @@ class MessageDictTest(ZulipTestCase):
def test_applying_markdown(self): def test_applying_markdown(self):
# type: () -> None # type: () -> None
sender = get_user_profile_by_email('othello@zulip.com') sender = self.example_user('othello')
receiver = get_user_profile_by_email('hamlet@zulip.com') receiver = self.example_user('hamlet')
recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL) recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
sending_client = make_client(name="test suite") sending_client = make_client(name="test suite")
message = Message( message = Message(
@@ -637,8 +637,8 @@ class MessageDictTest(ZulipTestCase):
# type: (Any) -> None # type: (Any) -> None
# pretend the converter returned an invalid message without raising an exception # pretend the converter returned an invalid message without raising an exception
convert_mock.return_value = None convert_mock.return_value = None
sender = get_user_profile_by_email('othello@zulip.com') sender = self.example_user('othello')
receiver = get_user_profile_by_email('hamlet@zulip.com') receiver = self.example_user('hamlet')
recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL) recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
sending_client = make_client(name="test suite") sending_client = make_client(name="test suite")
message = Message( message = Message(
@@ -662,8 +662,8 @@ class MessageDictTest(ZulipTestCase):
def test_reaction(self): def test_reaction(self):
# type: () -> None # type: () -> None
sender = get_user_profile_by_email('othello@zulip.com') sender = self.example_user('othello')
receiver = get_user_profile_by_email('hamlet@zulip.com') receiver = self.example_user('hamlet')
recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL) recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
sending_client = make_client(name="test suite") sending_client = make_client(name="test suite")
message = Message( message = Message(
@@ -697,8 +697,8 @@ class MessageDictTest(ZulipTestCase):
class SewMessageAndReactionTest(ZulipTestCase): class SewMessageAndReactionTest(ZulipTestCase):
def test_sew_messages_and_reaction(self): def test_sew_messages_and_reaction(self):
# type: () -> None # type: () -> None
sender = get_user_profile_by_email('othello@zulip.com') sender = self.example_user('othello')
receiver = get_user_profile_by_email('hamlet@zulip.com') receiver = self.example_user('hamlet')
pm_recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL) pm_recipient = Recipient.objects.get(type_id=receiver.id, type=Recipient.PERSONAL)
stream_name = u'Çiğdem' stream_name = u'Çiğdem'
stream = self.make_stream(stream_name) stream = self.make_stream(stream_name)
@@ -1246,7 +1246,7 @@ class EditMessageTest(ZulipTestCase):
"""This test verifies the accuracy of construction of Zulip's edit """This test verifies the accuracy of construction of Zulip's edit
history data structures.""" history data structures."""
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
hamlet = get_user_profile_by_email("hamlet@zulip.com") hamlet = self.example_user('hamlet')
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM, msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM,
subject="subject 1", content="content 1") subject="subject 1", content="content 1")
result = self.client_patch("/json/messages/" + str(msg_id), { result = self.client_patch("/json/messages/" + str(msg_id), {
@@ -1302,7 +1302,7 @@ class EditMessageTest(ZulipTestCase):
self.assert_json_success(result) self.assert_json_success(result)
history = ujson.loads(Message.objects.get(id=msg_id).edit_history) history = ujson.loads(Message.objects.get(id=msg_id).edit_history)
self.assertEqual(history[0]['prev_subject'], 'subject 3') self.assertEqual(history[0]['prev_subject'], 'subject 3')
self.assertEqual(history[0]['user_id'], get_user_profile_by_email("iago@zulip.com").id) self.assertEqual(history[0]['user_id'], self.example_user('iago').id)
history = ujson.loads(Message.objects.get(id=msg_id).edit_history) history = ujson.loads(Message.objects.get(id=msg_id).edit_history)
self.assertEqual(history[0]['prev_subject'], 'subject 3') self.assertEqual(history[0]['prev_subject'], 'subject 3')
@@ -1480,13 +1480,13 @@ class EditMessageTest(ZulipTestCase):
self.check_message(id5, subject="edited") self.check_message(id5, subject="edited")
self.check_message(id6, subject="topic3") self.check_message(id6, subject="topic3")
class MirroredMessageUsersTest(TestCase): class MirroredMessageUsersTest(ZulipTestCase):
class Request(object): class Request(object):
pass pass
def test_invalid_sender(self): def test_invalid_sender(self):
# type: () -> None # type: () -> None
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
recipients = [] # type: List[Text] recipients = [] # type: List[Text]
request = self.Request() request = self.Request()
request.POST = dict() # no sender request.POST = dict() # no sender
@@ -1501,7 +1501,7 @@ class MirroredMessageUsersTest(TestCase):
# type: () -> None # type: () -> None
client = get_client(name='banned_mirror') # Invalid!!! client = get_client(name='banned_mirror') # Invalid!!!
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
sender = user sender = user
recipients = [] # type: List[Text] recipients = [] # type: List[Text]
@@ -1603,7 +1603,7 @@ class MirroredMessageUsersTest(TestCase):
# type: () -> None # type: () -> None
client = get_client(name='irc_mirror') client = get_client(name='irc_mirror')
sender = get_user_profile_by_email('hamlet@zulip.com') sender = self.example_user('hamlet')
user = sender user = sender
recipients = ['alice@zulip.com', 'bob@irc.zulip.com', 'cordelia@zulip.com'] recipients = ['alice@zulip.com', 'bob@irc.zulip.com', 'cordelia@zulip.com']
@@ -1633,7 +1633,7 @@ class MirroredMessageUsersTest(TestCase):
# type: () -> None # type: () -> None
client = get_client(name='jabber_mirror') client = get_client(name='jabber_mirror')
sender = get_user_profile_by_email('hamlet@zulip.com') sender = self.example_user('hamlet')
user = sender user = sender
recipients = ['alice@zulip.com', 'bob@zulip.com', 'cordelia@zulip.com'] recipients = ['alice@zulip.com', 'bob@zulip.com', 'cordelia@zulip.com']
@@ -1886,7 +1886,7 @@ class LogDictTest(ZulipTestCase):
class CheckMessageTest(ZulipTestCase): class CheckMessageTest(ZulipTestCase):
def test_basic_check_message_call(self): def test_basic_check_message_call(self):
# type: () -> None # type: () -> None
sender = get_user_profile_by_email('othello@zulip.com') sender = self.example_user('othello')
client = make_client(name="test suite") client = make_client(name="test suite")
stream_name = u'España y Francia' stream_name = u'España y Francia'
self.make_stream(stream_name) self.make_stream(stream_name)
@@ -1903,7 +1903,7 @@ class CheckMessageTest(ZulipTestCase):
# type: () -> None # type: () -> None
"""We send a PM to a bot's owner if their bot sends a message to """We send a PM to a bot's owner if their bot sends a message to
an unsubscribed stream""" an unsubscribed stream"""
parent = get_user_profile_by_email('othello@zulip.com') parent = self.example_user('othello')
bot = do_create_user( bot = do_create_user(
email='othello-bot@zulip.com', email='othello-bot@zulip.com',
password='', password='',

View File

@@ -72,7 +72,7 @@ class NarrowBuilderTest(ZulipTestCase):
def setUp(self): def setUp(self):
# type: () -> None # type: () -> None
self.realm = get_realm('zulip') self.realm = get_realm('zulip')
self.user_profile = get_user_profile_by_email("hamlet@zulip.com") self.user_profile = self.example_user('hamlet')
self.builder = NarrowBuilder(self.user_profile, column('id')) self.builder = NarrowBuilder(self.user_profile, column('id'))
self.raw_query = select([column("id")], None, table("zerver_message")) self.raw_query = select([column("id")], None, table("zerver_message"))
@@ -420,8 +420,8 @@ class GetOldMessagesTest(ZulipTestCase):
def get_query_ids(self): def get_query_ids(self):
# type: () -> Dict[Text, int] # type: () -> Dict[Text, int]
hamlet_user = get_user_profile_by_email('hamlet@zulip.com') hamlet_user = self.example_user('hamlet')
othello_user = get_user_profile_by_email('othello@zulip.com') othello_user = self.example_user('othello')
query_ids = {} # type: Dict[Text, int] query_ids = {} # type: Dict[Text, int]
@@ -543,7 +543,7 @@ class GetOldMessagesTest(ZulipTestCase):
# narrow view. # narrow view.
self.subscribe_to_stream("hamlet@zulip.com", 'Scotland') self.subscribe_to_stream("hamlet@zulip.com", 'Scotland')
self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM) self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM)
messages = get_user_messages(get_user_profile_by_email("hamlet@zulip.com")) messages = get_user_messages(self.example_user('hamlet'))
stream_messages = [msg for msg in messages if msg.recipient.type == Recipient.STREAM] stream_messages = [msg for msg in messages if msg.recipient.type == Recipient.STREAM]
stream_name = get_display_recipient(stream_messages[0].recipient) stream_name = get_display_recipient(stream_messages[0].recipient)
stream_id = stream_messages[0].recipient.id stream_id = stream_messages[0].recipient.id
@@ -1066,7 +1066,7 @@ class GetOldMessagesTest(ZulipTestCase):
def common_check_get_messages_query(self, query_params, expected): def common_check_get_messages_query(self, query_params, expected):
# type: (Dict[str, object], Text) -> None # type: (Dict[str, object], Text) -> None
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
request = POSTRequestMock(query_params, user_profile) request = POSTRequestMock(query_params, user_profile)
with queries_captured() as queries: with queries_captured() as queries:
get_messages_backend(request, user_profile) get_messages_backend(request, user_profile)
@@ -1080,7 +1080,7 @@ class GetOldMessagesTest(ZulipTestCase):
def test_use_first_unread_anchor_with_some_unread_messages(self): def test_use_first_unread_anchor_with_some_unread_messages(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
# Have Othello send messages to Hamlet that he hasn't read. # Have Othello send messages to Hamlet that he hasn't read.
self.send_message("othello@zulip.com", "Scotland", Recipient.STREAM) self.send_message("othello@zulip.com", "Scotland", Recipient.STREAM)
@@ -1117,7 +1117,7 @@ class GetOldMessagesTest(ZulipTestCase):
def test_use_first_unread_anchor_with_no_unread_messages(self): def test_use_first_unread_anchor_with_no_unread_messages(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
query_params = dict( query_params = dict(
use_first_unread_anchor='true', use_first_unread_anchor='true',
@@ -1155,7 +1155,7 @@ class GetOldMessagesTest(ZulipTestCase):
realm = get_realm('zulip') realm = get_realm('zulip')
self.make_stream('web stuff') self.make_stream('web stuff')
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
user_profile.muted_topics = ujson.dumps([['Scotland', 'golf'], ['web stuff', 'css'], ['bogus', 'bogus']]) user_profile.muted_topics = ujson.dumps([['Scotland', 'golf'], ['web stuff', 'css'], ['bogus', 'bogus']])
user_profile.save() user_profile.save()
@@ -1192,7 +1192,7 @@ class GetOldMessagesTest(ZulipTestCase):
# type: () -> None # type: () -> None
realm = get_realm('zulip') realm = get_realm('zulip')
self.make_stream('web stuff') self.make_stream('web stuff')
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
# Test the do-nothing case first. # Test the do-nothing case first.
user_profile.muted_topics = ujson.dumps([['irrelevant_stream', 'irrelevant_topic']]) user_profile.muted_topics = ujson.dumps([['irrelevant_stream', 'irrelevant_topic']])

View File

@@ -31,8 +31,8 @@ class TestMissedMessages(ZulipTestCase):
def _test_cases(self, tokens, msg_id, body, send_as_user): def _test_cases(self, tokens, msg_id, body, send_as_user):
# type: (List[str], int, str, bool) -> None # type: (List[str], int, str, bool) -> None
othello = get_user_profile_by_email('othello@zulip.com') othello = self.example_user('othello')
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}]) handle_missedmessage_emails(hamlet.id, [{'message_id': msg_id}])
if settings.EMAIL_GATEWAY_PATTERN != "": if settings.EMAIL_GATEWAY_PATTERN != "":
reply_to_addresses = [settings.EMAIL_GATEWAY_PATTERN % (u'mm' + t) for t in tokens] reply_to_addresses = [settings.EMAIL_GATEWAY_PATTERN % (u'mm' + t) for t in tokens]
@@ -122,7 +122,7 @@ class TestMissedMessages(ZulipTestCase):
msg_id = self.send_message("othello@zulip.com", "denmark", Recipient.STREAM, msg_id = self.send_message("othello@zulip.com", "denmark", Recipient.STREAM,
'@**hamlet** to be deleted') '@**hamlet** to be deleted')
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
self.login("othello@zulip.com") self.login("othello@zulip.com")
result = self.client_patch('/json/messages/' + str(msg_id), result = self.client_patch('/json/messages/' + str(msg_id),
{'message_id': msg_id, 'content': ' '}) {'message_id': msg_id, 'content': ' '})
@@ -139,7 +139,7 @@ class TestMissedMessages(ZulipTestCase):
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL,
'Extremely personal message! to be deleted!') 'Extremely personal message! to be deleted!')
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
self.login("othello@zulip.com") self.login("othello@zulip.com")
result = self.client_patch('/json/messages/' + str(msg_id), result = self.client_patch('/json/messages/' + str(msg_id),
{'message_id': msg_id, 'content': ' '}) {'message_id': msg_id, 'content': ' '})
@@ -156,8 +156,8 @@ class TestMissedMessages(ZulipTestCase):
msg_id = self.send_message("othello@zulip.com", ["hamlet@zulip.com", "iago@zulip.com"], msg_id = self.send_message("othello@zulip.com", ["hamlet@zulip.com", "iago@zulip.com"],
Recipient.PERSONAL, 'Group personal message!') Recipient.PERSONAL, 'Group personal message!')
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
iago = get_user_profile_by_email('iago@zulip.com') iago = self.example_user('iago')
self.login("othello@zulip.com") self.login("othello@zulip.com")
result = self.client_patch('/json/messages/' + str(msg_id), result = self.client_patch('/json/messages/' + str(msg_id),
{'message_id': msg_id, 'content': ' '}) {'message_id': msg_id, 'content': ' '})

View File

@@ -233,7 +233,7 @@ class SingleUserPresenceTests(ZulipTestCase):
result = self.client_get("/json/users/cordelia@zulip.com/presence") result = self.client_get("/json/users/cordelia@zulip.com/presence")
self.assert_json_error(result, "No presence data for cordelia@zulip.com") self.assert_json_error(result, "No presence data for cordelia@zulip.com")
do_deactivate_user(get_user_profile_by_email("cordelia@zulip.com")) do_deactivate_user(self.example_user('cordelia'))
result = self.client_get("/json/users/cordelia@zulip.com/presence") result = self.client_get("/json/users/cordelia@zulip.com/presence")
self.assert_json_error(result, "No such user") self.assert_json_error(result, "No such user")

View File

@@ -16,7 +16,7 @@ from zerver.lib.test_classes import ZulipTestCase
from zerver.models import get_client, get_user_profile_by_email, UserActivity from zerver.models import get_client, get_user_profile_by_email, UserActivity
from zerver.worker import queue_processors from zerver.worker import queue_processors
class WorkerTest(TestCase): class WorkerTest(ZulipTestCase):
class FakeClient(object): class FakeClient(object):
def __init__(self): def __init__(self):
# type: () -> None # type: () -> None
@@ -66,7 +66,7 @@ class WorkerTest(TestCase):
# type: () -> None # type: () -> None
fake_client = self.FakeClient() fake_client = self.FakeClient()
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
UserActivity.objects.filter( UserActivity.objects.filter(
user_profile = user.id, user_profile = user.id,
client = get_client('ios') client = get_client('ios')

View File

@@ -29,7 +29,7 @@ class RealmTest(ZulipTestCase):
"""The main complicated thing about setting realm names is fighting the """The main complicated thing about setting realm names is fighting the
cache, and we start by populating the cache for Hamlet, and we end cache, and we start by populating the cache for Hamlet, and we end
by checking the cache to ensure that the new value is there.""" by checking the cache to ensure that the new value is there."""
get_user_profile_by_email('hamlet@zulip.com') self.example_user('hamlet')
realm = get_realm('zulip') realm = get_realm('zulip')
new_name = u'Zed You Elle Eye Pea' new_name = u'Zed You Elle Eye Pea'
do_set_realm_property(realm, 'name', new_name) do_set_realm_property(realm, 'name', new_name)
@@ -135,10 +135,10 @@ class RealmTest(ZulipTestCase):
Hamlet, and we end by checking the cache to ensure that his Hamlet, and we end by checking the cache to ensure that his
realm appears to be deactivated. You can make this test fail realm appears to be deactivated. You can make this test fail
by disabling cache.flush_realm().""" by disabling cache.flush_realm()."""
get_user_profile_by_email('hamlet@zulip.com') self.example_user('hamlet')
realm = get_realm('zulip') realm = get_realm('zulip')
do_deactivate_realm(realm) do_deactivate_realm(realm)
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertTrue(user.realm.deactivated) self.assertTrue(user.realm.deactivated)
def test_change_realm_default_language(self): def test_change_realm_default_language(self):

View File

@@ -23,19 +23,19 @@ class ChangeSettingsTest(ZulipTestCase):
def check_for_toggle_param(self, pattern, param): def check_for_toggle_param(self, pattern, param):
# type: (str, str) -> None # type: (str, str) -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
json_result = self.client_post(pattern, json_result = self.client_post(pattern,
{param: ujson.dumps(True)}) {param: ujson.dumps(True)})
self.assert_json_success(json_result) self.assert_json_success(json_result)
# refetch user_profile object to correctly handle caching # refetch user_profile object to correctly handle caching
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.assertEqual(getattr(user_profile, param), True) self.assertEqual(getattr(user_profile, param), True)
json_result = self.client_post(pattern, json_result = self.client_post(pattern,
{param: ujson.dumps(False)}) {param: ujson.dumps(False)})
self.assert_json_success(json_result) self.assert_json_success(json_result)
# refetch user_profile object to correctly handle caching # refetch user_profile object to correctly handle caching
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.assertEqual(getattr(user_profile, param), False) self.assertEqual(getattr(user_profile, param), False)
# TODO: requires method consolidation, right now, there's no alternative # TODO: requires method consolidation, right now, there's no alternative
@@ -43,19 +43,19 @@ class ChangeSettingsTest(ZulipTestCase):
def check_for_toggle_param_patch(self, pattern, param): def check_for_toggle_param_patch(self, pattern, param):
# type: (str, str) -> None # type: (str, str) -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
json_result = self.client_patch(pattern, json_result = self.client_patch(pattern,
{param: ujson.dumps(True)}) {param: ujson.dumps(True)})
self.assert_json_success(json_result) self.assert_json_success(json_result)
# refetch user_profile object to correctly handle caching # refetch user_profile object to correctly handle caching
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.assertEqual(getattr(user_profile, param), True) self.assertEqual(getattr(user_profile, param), True)
json_result = self.client_patch(pattern, json_result = self.client_patch(pattern,
{param: ujson.dumps(False)}) {param: ujson.dumps(False)})
self.assert_json_success(json_result) self.assert_json_success(json_result)
# refetch user_profile object to correctly handle caching # refetch user_profile object to correctly handle caching
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.assertEqual(getattr(user_profile, param), False) self.assertEqual(getattr(user_profile, param), False)
def test_successful_change_settings(self): def test_successful_change_settings(self):
@@ -76,11 +76,11 @@ class ChangeSettingsTest(ZulipTestCase):
self.assert_json_success(json_result) self.assert_json_success(json_result)
result = ujson.loads(json_result.content) result = ujson.loads(json_result.content)
self.check_well_formed_change_settings_response(result) self.check_well_formed_change_settings_response(result)
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com"). self.assertEqual(self.example_user('hamlet').
full_name, "Foo Bar") full_name, "Foo Bar")
self.logout() self.logout()
self.login("hamlet@zulip.com", "foobar1") self.login("hamlet@zulip.com", "foobar1")
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
def test_illegal_name_changes(self): def test_illegal_name_changes(self):

View File

@@ -146,7 +146,7 @@ class PasswordResetTest(ZulipTestCase):
# log back in with new password # log back in with new password
self.login(email, password='new_password') self.login(email, password='new_password')
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
# make sure old password no longer works # make sure old password no longer works
@@ -234,7 +234,7 @@ class LoginTest(ZulipTestCase):
def test_login(self): def test_login(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(get_session_dict_user(self.client.session), user_profile.id) self.assertEqual(get_session_dict_user(self.client.session), user_profile.id)
def test_login_bad_password(self): def test_login_bad_password(self):
@@ -473,7 +473,7 @@ class InviteUserTest(ZulipTestCase):
history but only from public streams. history but only from public streams.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
private_stream_name = "Secret" private_stream_name = "Secret"
self.make_stream(private_stream_name, invite_only=True) self.make_stream(private_stream_name, invite_only=True)
self.subscribe_to_stream(user_profile.email, private_stream_name) self.subscribe_to_stream(user_profile.email, private_stream_name)
@@ -667,7 +667,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
def test_refer_friend(self): def test_refer_friend(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
user.invites_granted = 1 user.invites_granted = 1
user.invites_used = 0 user.invites_used = 0
user.save() user.save()
@@ -679,13 +679,13 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
# verify this works # verify this works
Referral.objects.get(user_profile=user, email=invitee) Referral.objects.get(user_profile=user, email=invitee)
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertEqual(user.invites_used, 1) self.assertEqual(user.invites_used, 1)
def test_refer_friend_no_email(self): def test_refer_friend_no_email(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
user.invites_granted = 1 user.invites_granted = 1
user.invites_used = 0 user.invites_used = 0
user.save() user.save()
@@ -694,13 +694,13 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
self.client_post('/json/refer_friend', dict(email='')), self.client_post('/json/refer_friend', dict(email='')),
"No email address specified") "No email address specified")
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertEqual(user.invites_used, 0) self.assertEqual(user.invites_used, 0)
def test_refer_friend_no_invites(self): def test_refer_friend_no_invites(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
user.invites_granted = 1 user.invites_granted = 1
user.invites_used = 1 user.invites_used = 1
user.save() user.save()
@@ -710,7 +710,7 @@ so we didn't send them an invitation. We did send invitations to everyone else!"
self.client_post('/json/refer_friend', dict(email=invitee)), self.client_post('/json/refer_friend', dict(email=invitee)),
"Insufficient invites") "Insufficient invites")
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertEqual(user.invites_used, 1) self.assertEqual(user.invites_used, 1)
def test_invitation_reminder_email(self): def test_invitation_reminder_email(self):
@@ -790,7 +790,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
self.assert_in_response('Unknown email unsubscribe request', result) self.assert_in_response('Unknown email unsubscribe request', result)
# An unknown message type "fake" produces an error. # An unknown message type "fake" produces an error.
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
unsubscribe_link = one_click_unsubscribe_link(user_profile, "fake") unsubscribe_link = one_click_unsubscribe_link(user_profile, "fake")
result = self.client_get(urllib.parse.urlparse(unsubscribe_link).path) result = self.client_get(urllib.parse.urlparse(unsubscribe_link).path)
self.assert_in_response('Unknown email unsubscribe request', result) self.assert_in_response('Unknown email unsubscribe request', result)
@@ -802,7 +802,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
e-mails that you can click even when logged out to update your e-mails that you can click even when logged out to update your
email notification settings. email notification settings.
""" """
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
user_profile.enable_offline_email_notifications = True user_profile.enable_offline_email_notifications = True
user_profile.save() user_profile.save()
@@ -822,7 +822,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
click even when logged out to stop receiving them. click even when logged out to stop receiving them.
""" """
email = "hamlet@zulip.com" email = "hamlet@zulip.com"
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
# Simulate a new user signing up, which enqueues 2 welcome e-mails. # Simulate a new user signing up, which enqueues 2 welcome e-mails.
enqueue_welcome_emails(email, "King Hamlet") enqueue_welcome_emails(email, "King Hamlet")
@@ -848,7 +848,7 @@ class EmailUnsubscribeTests(ZulipTestCase):
have been queued. have been queued.
""" """
email = "hamlet@zulip.com" email = "hamlet@zulip.com"
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.assertTrue(user_profile.enable_digest_emails) self.assertTrue(user_profile.enable_digest_emails)
# Enqueue a fake digest email. # Enqueue a fake digest email.
@@ -1599,11 +1599,11 @@ class DeactivateUserTest(ZulipTestCase):
# type: () -> None # type: () -> None
email = 'hamlet@zulip.com' email = 'hamlet@zulip.com'
self.login(email) self.login(email)
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
result = self.client_delete('/json/users/me') result = self.client_delete('/json/users/me')
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertFalse(user.is_active) self.assertFalse(user.is_active)
self.login(email, fails=True) self.login(email, fails=True)
@@ -1611,15 +1611,15 @@ class DeactivateUserTest(ZulipTestCase):
# type: () -> None # type: () -> None
email = 'iago@zulip.com' email = 'iago@zulip.com'
self.login(email) self.login(email)
user = get_user_profile_by_email('iago@zulip.com') user = self.example_user('iago')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
result = self.client_delete('/json/users/me') result = self.client_delete('/json/users/me')
self.assert_json_error(result, "Cannot deactivate the only organization administrator") self.assert_json_error(result, "Cannot deactivate the only organization administrator")
user = get_user_profile_by_email('iago@zulip.com') user = self.example_user('iago')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
self.assertTrue(user.is_realm_admin) self.assertTrue(user.is_realm_admin)
email = 'hamlet@zulip.com' email = 'hamlet@zulip.com'
user_2 = get_user_profile_by_email('hamlet@zulip.com') user_2 = self.example_user('hamlet')
do_change_is_admin(user_2, True) do_change_is_admin(user_2, True)
self.assertTrue(user_2.is_realm_admin) self.assertTrue(user_2.is_realm_admin)
result = self.client_delete('/json/users/me') result = self.client_delete('/json/users/me')
@@ -1757,7 +1757,7 @@ class MobileAuthOTPTest(ZulipTestCase):
def test_otp_encrypt_api_key(self): def test_otp_encrypt_api_key(self):
# type: () -> None # type: () -> None
hamlet = get_user_profile_by_email("hamlet@zulip.com") hamlet = self.example_user('hamlet')
hamlet.api_key = '12ac' * 8 hamlet.api_key = '12ac' * 8
otp = '7be38894' * 8 otp = '7be38894' * 8
result = otp_encrypt_api_key(hamlet, otp) result = otp_encrypt_api_key(hamlet, otp)

View File

@@ -260,8 +260,8 @@ class StreamAdminTest(ZulipTestCase):
# Should be just a description change event # Should be just a description change event
self.assert_length(events, 1) self.assert_length(events, 1)
cordelia = get_user_profile_by_email('cordelia@zulip.com') cordelia = self.example_user('cordelia')
prospero = get_user_profile_by_email('prospero@zulip.com') prospero = self.example_user('prospero')
notified_user_ids = set(events[-1]['users']) notified_user_ids = set(events[-1]['users'])
self.assertIn(user_profile.id, notified_user_ids) self.assertIn(user_profile.id, notified_user_ids)
@@ -332,7 +332,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertEqual(notified_user_ids, set(active_user_ids(realm))) self.assertEqual(notified_user_ids, set(active_user_ids(realm)))
self.assertIn(user_profile.id, self.assertIn(user_profile.id,
notified_user_ids) notified_user_ids)
self.assertIn(get_user_profile_by_email('prospero@zulip.com').id, self.assertIn(self.example_user('prospero').id,
notified_user_ids) notified_user_ids)
# Test case to handle unicode stream name change # Test case to handle unicode stream name change
@@ -421,7 +421,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertEqual(notified_user_ids, set(active_user_ids(realm))) self.assertEqual(notified_user_ids, set(active_user_ids(realm)))
self.assertIn(user_profile.id, self.assertIn(user_profile.id,
notified_user_ids) notified_user_ids)
self.assertIn(get_user_profile_by_email('prospero@zulip.com').id, self.assertIn(self.example_user('prospero').id,
notified_user_ids) notified_user_ids)
self.assertEqual('Test description', stream.description) self.assertEqual('Test description', stream.description)
@@ -780,7 +780,7 @@ class DefaultStreamTest(ZulipTestCase):
def test_api_calls(self): def test_api_calls(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
do_change_is_admin(user_profile, True) do_change_is_admin(user_profile, True)
stream_name = 'stream ADDED via api' stream_name = 'stream ADDED via api'
(stream, _) = create_stream_if_needed(user_profile.realm, stream_name) (stream, _) = create_stream_if_needed(user_profile.realm, stream_name)
@@ -1166,7 +1166,7 @@ class SubscriptionRestApiTest(ZulipTestCase):
here with a simple scenario to avoid false positives related to here with a simple scenario to avoid false positives related to
subscription complications. subscription complications.
''' '''
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
user_profile.full_name = 'Hamlet' user_profile.full_name = 'Hamlet'
user_profile.save() user_profile.save()
@@ -1183,7 +1183,7 @@ class SubscriptionRestApiTest(ZulipTestCase):
with self.assertRaises(JsonableError): with self.assertRaises(JsonableError):
compose_views(None, user_profile, [(method1, {}), (method2, {})]) compose_views(None, user_profile, [(method1, {}), (method2, {})])
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assertEqual(user_profile.full_name, 'Hamlet') self.assertEqual(user_profile.full_name, 'Hamlet')
class SubscriptionAPITest(ZulipTestCase): class SubscriptionAPITest(ZulipTestCase):
@@ -1386,7 +1386,7 @@ class SubscriptionAPITest(ZulipTestCase):
invite_streams = ["cross_stream"] invite_streams = ["cross_stream"]
user = get_user_profile_by_email("AARON@zulip.com") user = self.example_user('AARON')
user.realm = realm user.realm = realm
user.save() user.save()

View File

@@ -22,11 +22,11 @@ class PointerTest(ZulipTestCase):
the pointer we store for your UserProfile. the pointer we store for your UserProfile.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
msg_id = self.send_message("othello@zulip.com", "Verona", Recipient.STREAM) msg_id = self.send_message("othello@zulip.com", "Verona", Recipient.STREAM)
result = self.client_post("/json/users/me/pointer", {"pointer": msg_id}) result = self.client_post("/json/users/me/pointer", {"pointer": msg_id})
self.assert_json_success(result) self.assert_json_success(result)
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, msg_id) self.assertEqual(self.example_user('hamlet').pointer, msg_id)
def test_api_update_pointer(self): def test_api_update_pointer(self):
# type: () -> None # type: () -> None
@@ -48,10 +48,10 @@ class PointerTest(ZulipTestCase):
returns a 400 and error message. returns a 400 and error message.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
result = self.client_post("/json/users/me/pointer", {"foo": 1}) result = self.client_post("/json/users/me/pointer", {"foo": 1})
self.assert_json_error(result, "Missing 'pointer' argument") self.assert_json_error(result, "Missing 'pointer' argument")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
def test_invalid_pointer(self): def test_invalid_pointer(self):
# type: () -> None # type: () -> None
@@ -60,10 +60,10 @@ class PointerTest(ZulipTestCase):
message. message.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
result = self.client_post("/json/users/me/pointer", {"pointer": "foo"}) result = self.client_post("/json/users/me/pointer", {"pointer": "foo"})
self.assert_json_error(result, "Bad value for 'pointer': foo") self.assert_json_error(result, "Bad value for 'pointer': foo")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
def test_pointer_out_of_range(self): def test_pointer_out_of_range(self):
# type: () -> None # type: () -> None
@@ -72,10 +72,10 @@ class PointerTest(ZulipTestCase):
and error message. and error message.
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
result = self.client_post("/json/users/me/pointer", {"pointer": -2}) result = self.client_post("/json/users/me/pointer", {"pointer": -2})
self.assert_json_error(result, "Bad value for 'pointer': -2") self.assert_json_error(result, "Bad value for 'pointer': -2")
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
def test_use_first_unread_anchor_interaction_with_pointer(self): def test_use_first_unread_anchor_interaction_with_pointer(self):
# type: () -> None # type: () -> None
@@ -86,7 +86,7 @@ class PointerTest(ZulipTestCase):
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
# Ensure the pointer is not set (-1) # Ensure the pointer is not set (-1)
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, -1) self.assertEqual(self.example_user('hamlet').pointer, -1)
# Mark all existing messages as read # Mark all existing messages as read
result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]), result = self.client_post("/json/messages/flags", {"messages": ujson.dumps([]),
"op": "add", "op": "add",
@@ -115,7 +115,7 @@ class PointerTest(ZulipTestCase):
# Verify the message is marked as read # Verify the message is marked as read
user_message = UserMessage.objects.get( user_message = UserMessage.objects.get(
message_id=old_message_id, message_id=old_message_id,
user_profile=get_user_profile_by_email("hamlet@zulip.com")) user_profile=self.example_user('hamlet'))
self.assertTrue(user_message.flags.read) self.assertTrue(user_message.flags.read)
# Let's set this old message to be unread # Let's set this old message to be unread
@@ -127,7 +127,7 @@ class PointerTest(ZulipTestCase):
# Verify it's now marked as unread # Verify it's now marked as unread
user_message = UserMessage.objects.get( user_message = UserMessage.objects.get(
message_id=old_message_id, message_id=old_message_id,
user_profile=get_user_profile_by_email("hamlet@zulip.com")) user_profile=self.example_user('hamlet'))
self.assert_json_success(result) self.assert_json_success(result)
self.assertFalse(user_message.flags.read) self.assertFalse(user_message.flags.read)
@@ -142,13 +142,13 @@ class PointerTest(ZulipTestCase):
result = self.client_post("/json/users/me/pointer", result = self.client_post("/json/users/me/pointer",
{"pointer": next_old_message_id}) {"pointer": next_old_message_id})
self.assert_json_success(result) self.assert_json_success(result)
self.assertEqual(get_user_profile_by_email("hamlet@zulip.com").pointer, self.assertEqual(self.example_user('hamlet').pointer,
next_old_message_id) next_old_message_id)
# Verify that moving the pointer didn't mark our message as read. # Verify that moving the pointer didn't mark our message as read.
user_message = UserMessage.objects.get( user_message = UserMessage.objects.get(
message_id=old_message_id, message_id=old_message_id,
user_profile=get_user_profile_by_email("hamlet@zulip.com")) user_profile=self.example_user('hamlet'))
self.assertFalse(user_message.flags.read) self.assertFalse(user_message.flags.read)
# Now if we call get_messages with use_first_unread_anchor=True, # Now if we call get_messages with use_first_unread_anchor=True,
@@ -236,7 +236,7 @@ class UnreadCountTests(ZulipTestCase):
def test_mark_all_in_stream_read(self): def test_mark_all_in_stream_read(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm) self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
self.subscribe_to_stream("cordelia@zulip.com", "test_stream", user_profile.realm) self.subscribe_to_stream("cordelia@zulip.com", "test_stream", user_profile.realm)
@@ -288,7 +288,7 @@ class UnreadCountTests(ZulipTestCase):
def test_mark_all_in_stream_topic_read(self): def test_mark_all_in_stream_topic_read(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm) self.subscribe_to_stream(user_profile.email, "test_stream", user_profile.realm)
message_id = self.send_message("hamlet@zulip.com", "test_stream", Recipient.STREAM, "hello", "test_topic") message_id = self.send_message("hamlet@zulip.com", "test_stream", Recipient.STREAM, "hello", "test_topic")

View File

@@ -96,7 +96,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase):
and does so in a way that preserves 100% test coverage for Python 3. and does so in a way that preserves 100% test coverage for Python 3.
""" """
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
mock_file = mock.Mock() mock_file = mock.Mock()
mock_file._get_size = mock.Mock(return_value=1024) mock_file._get_size = mock.Mock(return_value=1024)
@@ -638,7 +638,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_gravatar_avatar(self): def test_get_gravatar_avatar(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
cordelia = get_user_profile_by_email('cordelia@zulip.com') cordelia = self.example_user('cordelia')
cordelia.avatar_source = UserProfile.AVATAR_FROM_GRAVATAR cordelia.avatar_source = UserProfile.AVATAR_FROM_GRAVATAR
cordelia.save() cordelia.save()
@@ -655,7 +655,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_user_avatar(self): def test_get_user_avatar(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
cordelia = get_user_profile_by_email('cordelia@zulip.com') cordelia = self.example_user('cordelia')
cordelia.avatar_source = UserProfile.AVATAR_FROM_USER cordelia.avatar_source = UserProfile.AVATAR_FROM_USER
cordelia.save() cordelia.save()
@@ -670,7 +670,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
def test_get_user_avatar_medium(self): def test_get_user_avatar_medium(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
cordelia = get_user_profile_by_email('cordelia@zulip.com') cordelia = self.example_user('cordelia')
cordelia.avatar_source = UserProfile.AVATAR_FROM_USER cordelia.avatar_source = UserProfile.AVATAR_FROM_USER
cordelia.save() cordelia.save()
@@ -720,7 +720,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
self.assertEqual(Image.open(io.BytesIO(data)).size, (100, 100)) self.assertEqual(Image.open(io.BytesIO(data)).size, (100, 100))
# Verify that the medium-size avatar was created # Verify that the medium-size avatar was created
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
medium_avatar_disk_path = avatar_disk_path(user_profile, medium=True) medium_avatar_disk_path = avatar_disk_path(user_profile, medium=True)
self.assertTrue(os.path.exists(medium_avatar_disk_path)) self.assertTrue(os.path.exists(medium_avatar_disk_path))
@@ -747,7 +747,7 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
result = self.client_put_multipart("/json/users/me/avatar", {'file': fp}) result = self.client_put_multipart("/json/users/me/avatar", {'file': fp})
self.assert_json_error(result, "Could not decode image; did you upload an image file?") self.assert_json_error(result, "Could not decode image; did you upload an image file?")
user_profile = get_user_profile_by_email("hamlet@zulip.com") user_profile = self.example_user('hamlet')
self.assertEqual(user_profile.avatar_version, 1) self.assertEqual(user_profile.avatar_version, 1)
def test_delete_avatar(self): def test_delete_avatar(self):
@@ -756,12 +756,12 @@ class AvatarTest(UploadSerializeMixin, ZulipTestCase):
A DELETE request to /json/users/me/avatar should delete the user avatar and return gravatar URL A DELETE request to /json/users/me/avatar should delete the user avatar and return gravatar URL
""" """
self.login("hamlet@zulip.com") self.login("hamlet@zulip.com")
hamlet = get_user_profile_by_email("hamlet@zulip.com") hamlet = self.example_user('hamlet')
hamlet.avatar_source = UserProfile.AVATAR_FROM_USER hamlet.avatar_source = UserProfile.AVATAR_FROM_USER
hamlet.save() hamlet.save()
result = self.client_delete("/json/users/me/avatar") result = self.client_delete("/json/users/me/avatar")
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)

View File

@@ -51,7 +51,7 @@ def find_dict(lst, k, v):
class PermissionTest(ZulipTestCase): class PermissionTest(ZulipTestCase):
def test_get_admin_users(self): def test_get_admin_users(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
do_change_is_admin(user_profile, False) do_change_is_admin(user_profile, False)
admin_users = user_profile.realm.get_admin_users() admin_users = user_profile.realm.get_admin_users()
self.assertFalse(user_profile in admin_users) self.assertFalse(user_profile in admin_users)
@@ -62,7 +62,7 @@ class PermissionTest(ZulipTestCase):
def test_updating_non_existent_user(self): def test_updating_non_existent_user(self):
# type: () -> None # type: () -> None
self.login('hamlet@zulip.com') self.login('hamlet@zulip.com')
admin = get_user_profile_by_email('hamlet@zulip.com') admin = self.example_user('hamlet')
do_change_is_admin(admin, True) do_change_is_admin(admin, True)
result = self.client_patch('/json/users/nonexistentuser@zulip.com', {}) result = self.client_patch('/json/users/nonexistentuser@zulip.com', {})
@@ -71,8 +71,8 @@ class PermissionTest(ZulipTestCase):
def test_admin_api(self): def test_admin_api(self):
# type: () -> None # type: () -> None
self.login('hamlet@zulip.com') self.login('hamlet@zulip.com')
admin = get_user_profile_by_email('hamlet@zulip.com') admin = self.example_user('hamlet')
user = get_user_profile_by_email('othello@zulip.com') user = self.example_user('othello')
realm = admin.realm realm = admin.realm
do_change_is_admin(admin, True) do_change_is_admin(admin, True)
@@ -138,7 +138,7 @@ class PermissionTest(ZulipTestCase):
req = dict(full_name=ujson.dumps(new_name)) req = dict(full_name=ujson.dumps(new_name))
result = self.client_patch('/json/users/hamlet@zulip.com', req) result = self.client_patch('/json/users/hamlet@zulip.com', req)
self.assertTrue(result.status_code == 200) self.assertTrue(result.status_code == 200)
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
self.assertEqual(hamlet.full_name, new_name) self.assertEqual(hamlet.full_name, new_name)
def test_non_admin_cannot_change_full_name(self): def test_non_admin_cannot_change_full_name(self):
@@ -238,11 +238,11 @@ class AdminCreateUserTest(ZulipTestCase):
self.assert_json_error(result, self.assert_json_error(result,
"Email 'romeo@zulip.net' already in use") "Email 'romeo@zulip.net' already in use")
class UserProfileTest(TestCase): class UserProfileTest(ZulipTestCase):
def test_get_emails_from_user_ids(self): def test_get_emails_from_user_ids(self):
# type: () -> None # type: () -> None
hamlet = get_user_profile_by_email('hamlet@zulip.com') hamlet = self.example_user('hamlet')
othello = get_user_profile_by_email('othello@zulip.com') othello = self.example_user('othello')
dct = get_emails_from_user_ids([hamlet.id, othello.id]) dct = get_emails_from_user_ids([hamlet.id, othello.id])
self.assertEqual(dct[hamlet.id], 'hamlet@zulip.com') self.assertEqual(dct[hamlet.id], 'hamlet@zulip.com')
self.assertEqual(dct[othello.id], 'othello@zulip.com') self.assertEqual(dct[othello.id], 'othello@zulip.com')
@@ -250,7 +250,7 @@ class UserProfileTest(TestCase):
class ActivateTest(ZulipTestCase): class ActivateTest(ZulipTestCase):
def test_basics(self): def test_basics(self):
# type: () -> None # type: () -> None
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
do_deactivate_user(user) do_deactivate_user(user)
self.assertFalse(user.is_active) self.assertFalse(user.is_active)
do_reactivate_user(user) do_reactivate_user(user)
@@ -258,21 +258,21 @@ class ActivateTest(ZulipTestCase):
def test_api(self): def test_api(self):
# type: () -> None # type: () -> None
admin = get_user_profile_by_email('othello@zulip.com') admin = self.example_user('othello')
do_change_is_admin(admin, True) do_change_is_admin(admin, True)
self.login('othello@zulip.com') self.login('othello@zulip.com')
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
result = self.client_delete('/json/users/hamlet@zulip.com') result = self.client_delete('/json/users/hamlet@zulip.com')
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertFalse(user.is_active) self.assertFalse(user.is_active)
result = self.client_post('/json/users/hamlet@zulip.com/reactivate') result = self.client_post('/json/users/hamlet@zulip.com/reactivate')
self.assert_json_success(result) self.assert_json_success(result)
user = get_user_profile_by_email('hamlet@zulip.com') user = self.example_user('hamlet')
self.assertTrue(user.is_active) self.assertTrue(user.is_active)
def test_api_me_user(self): def test_api_me_user(self):
@@ -294,7 +294,7 @@ class ActivateTest(ZulipTestCase):
def test_api_with_nonexistent_user(self): def test_api_with_nonexistent_user(self):
# type: () -> None # type: () -> None
admin = get_user_profile_by_email('othello@zulip.com') admin = self.example_user('othello')
do_change_is_admin(admin, True) do_change_is_admin(admin, True)
self.login('othello@zulip.com') self.login('othello@zulip.com')
@@ -318,7 +318,7 @@ class ActivateTest(ZulipTestCase):
def test_api_with_insufficient_permissions(self): def test_api_with_insufficient_permissions(self):
# type: () -> None # type: () -> None
non_admin = get_user_profile_by_email('othello@zulip.com') non_admin = self.example_user('othello')
do_change_is_admin(non_admin, False) do_change_is_admin(non_admin, False)
self.login('othello@zulip.com') self.login('othello@zulip.com')
@@ -370,7 +370,7 @@ class GetProfileTest(ZulipTestCase):
# type: () -> None # type: () -> None
with queries_captured() as queries: with queries_captured() as queries:
with simulated_empty_cache() as cache_queries: with simulated_empty_cache() as cache_queries:
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
self.assert_length(queries, 1) self.assert_length(queries, 1)
self.assert_length(cache_queries, 1) self.assert_length(cache_queries, 1)
@@ -426,7 +426,7 @@ class GetProfileTest(ZulipTestCase):
def test_get_all_profiles_avatar_urls(self): def test_get_all_profiles_avatar_urls(self):
# type: () -> None # type: () -> None
user_profile = get_user_profile_by_email('hamlet@zulip.com') user_profile = self.example_user('hamlet')
result = self.client_get("/api/v1/users", **self.api_auth('hamlet@zulip.com')) result = self.client_get("/api/v1/users", **self.api_auth('hamlet@zulip.com'))
self.assert_json_success(result) self.assert_json_success(result)
json = ujson.loads(result.content) json = ujson.loads(result.content)