tests: Replaced @zulip.com references with self.example_ functions.

This cleans up the excessive use of @zulip.com emails in the tests.
This commit is contained in:
Lech Kaiel
2017-05-24 03:08:49 +00:00
committed by Tim Abbott
parent aa576d83b0
commit 6b49e667ef
14 changed files with 178 additions and 136 deletions

View File

@@ -15,33 +15,34 @@ from zerver.models import Attachment
class AttachmentsTests(ZulipTestCase): class AttachmentsTests(ZulipTestCase):
def setUp(self): def setUp(self):
# type: () -> None # type: () -> None
user = self.example_user('cordelia') user_profile = 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_profile)
def test_list_by_user(self): def test_list_by_user(self):
# type: () -> None # type: () -> None
self.login("cordelia@zulip.com") user_profile = self.example_user('cordelia')
self.login(user_profile.email)
result = self.client_get('/json/attachments') result = self.client_get('/json/attachments')
self.assert_json_success(result) self.assert_json_success(result)
user = self.example_user('cordelia') attachments = user_attachments(user_profile)
attachments = user_attachments(user)
data = ujson.loads(result.content) data = ujson.loads(result.content)
self.assertEqual(data['attachments'], attachments) self.assertEqual(data['attachments'], attachments)
@mock.patch('zerver.lib.attachments.delete_message_image') @mock.patch('zerver.lib.attachments.delete_message_image')
def test_remove_attachment(self, ignored): def test_remove_attachment(self, ignored):
# type: (Any) -> None # type: (Any) -> None
self.login("cordelia@zulip.com") user_profile = self.example_user('cordelia')
self.login(user_profile.email)
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 = self.example_user('cordelia') attachments = user_attachments(user_profile)
attachments = user_attachments(user)
self.assertEqual(attachments, []) self.assertEqual(attachments, [])
def test_list_another_user(self): def test_list_another_user(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") user_profile = self.example_user('iago')
self.login(user_profile.email)
result = self.client_get('/json/attachments') result = self.client_get('/json/attachments')
self.assert_json_success(result) self.assert_json_success(result)
data = ujson.loads(result.content) data = ujson.loads(result.content)
@@ -49,11 +50,12 @@ class AttachmentsTests(ZulipTestCase):
def test_remove_another_user(self): def test_remove_another_user(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") user_profile = self.example_user('iago')
self.login(user_profile.email)
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 = self.example_user('cordelia') user_profile_to_remove = self.example_user('cordelia')
attachments = user_attachments(user) attachments = user_attachments(user_profile_to_remove)
self.assertEqual(attachments, [self.attachment.to_dict()]) self.assertEqual(attachments, [self.attachment.to_dict()])
def test_list_unauthenticated(self): def test_list_unauthenticated(self):

View File

@@ -4,7 +4,6 @@ from __future__ import absolute_import
import subprocess import subprocess
from django.http import HttpResponse from django.http import HttpResponse
from django.test import TestCase
from zerver.lib.test_helpers import ( from zerver.lib.test_helpers import (
most_recent_message, most_recent_message,
@@ -88,8 +87,8 @@ 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")
user_profile = self.example_user('hamlet') user_profile = self.example_user('hamlet')
self.login(user_profile.email)
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)
@@ -98,9 +97,9 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase):
incoming_valid_message = MIMEText('TestStreamEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275 incoming_valid_message = MIMEText('TestStreamEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275
incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject' incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject'
incoming_valid_message['From'] = "hamlet@zulip.com" incoming_valid_message['From'] = self.example_email('hamlet')
incoming_valid_message['To'] = stream_to_address incoming_valid_message['To'] = stream_to_address
incoming_valid_message['Reply-to'] = "othello@zulip.com" incoming_valid_message['Reply-to'] = self.example_email('othello')
process_message(incoming_valid_message) process_message(incoming_valid_message)
@@ -117,22 +116,22 @@ 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")
user_profile = self.example_user('hamlet') user_profile = self.example_user('hamlet')
self.login(user_profile.email)
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)
stream_to_address = encode_email_address(stream) stream_to_address = encode_email_address(stream)
headers = {} headers = {}
headers['Reply-To'] = 'othello@zulip.com' headers['Reply-To'] = self.example_email('othello')
# empty body # empty body
incoming_valid_message = MIMEText('') # type: Any # https://github.com/python/typeshed/issues/275 incoming_valid_message = MIMEText('') # type: Any # https://github.com/python/typeshed/issues/275
incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject' incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject'
incoming_valid_message['From'] = "hamlet@zulip.com" incoming_valid_message['From'] = self.example_email('hamlet')
incoming_valid_message['To'] = stream_to_address incoming_valid_message['To'] = stream_to_address
incoming_valid_message['Reply-to'] = "othello@zulip.com" incoming_valid_message['Reply-to'] = self.example_email('othello')
exception_message = "" exception_message = ""
debug_info = {} # type: Dict[str, Any] debug_info = {} # type: Dict[str, Any]
@@ -156,11 +155,12 @@ class TestMissedPersonalMessageEmailMessages(ZulipTestCase):
# build dummy messages for missed messages email reply # build dummy messages for missed messages email reply
# have Hamlet send Othello a PM. Othello will reply via email # have Hamlet send Othello a PM. Othello will reply via email
# Hamlet will receive the message. # Hamlet will receive the message.
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
result = self.client_post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": self.example_email('othello')})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = self.example_user('othello') user_profile = self.example_user('othello')
@@ -173,9 +173,9 @@ class TestMissedPersonalMessageEmailMessages(ZulipTestCase):
incoming_valid_message = MIMEText('TestMissedMessageEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275 incoming_valid_message = MIMEText('TestMissedMessageEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275
incoming_valid_message['Subject'] = 'TestMissedMessageEmailMessages Subject' incoming_valid_message['Subject'] = 'TestMissedMessageEmailMessages Subject'
incoming_valid_message['From'] = "othello@zulip.com" incoming_valid_message['From'] = self.example_email('othello')
incoming_valid_message['To'] = mm_address incoming_valid_message['To'] = mm_address
incoming_valid_message['Reply-to'] = "othello@zulip.com" incoming_valid_message['Reply-to'] = self.example_email('othello')
process_message(incoming_valid_message) process_message(incoming_valid_message)
@@ -196,12 +196,13 @@ class TestMissedHuddleMessageEmailMessages(ZulipTestCase):
# build dummy messages for missed messages email reply # build dummy messages for missed messages email reply
# have Othello send Iago and Cordelia a PM. Cordelia will reply via email # have Othello send Iago and Cordelia a PM. Cordelia will reply via email
# Iago and Othello will receive the message. # Iago and Othello will receive the message.
self.login("othello@zulip.com") email = self.example_email('othello')
self.login(email)
result = self.client_post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": ujson.dumps(["cordelia@zulip.com", "to": ujson.dumps([self.example_email('cordelia'),
"iago@zulip.com"])}) self.example_email('iago')])})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = self.example_user('cordelia') user_profile = self.example_user('cordelia')
@@ -214,9 +215,9 @@ class TestMissedHuddleMessageEmailMessages(ZulipTestCase):
incoming_valid_message = MIMEText('TestMissedHuddleMessageEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275 incoming_valid_message = MIMEText('TestMissedHuddleMessageEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275
incoming_valid_message['Subject'] = 'TestMissedHuddleMessageEmailMessages Subject' incoming_valid_message['Subject'] = 'TestMissedHuddleMessageEmailMessages Subject'
incoming_valid_message['From'] = "cordelia@zulip.com" incoming_valid_message['From'] = self.example_email('cordelia')
incoming_valid_message['To'] = mm_address incoming_valid_message['To'] = mm_address
incoming_valid_message['Reply-to'] = "cordelia@zulip.com" incoming_valid_message['Reply-to'] = self.example_email('cordelia')
process_message(incoming_valid_message) process_message(incoming_valid_message)
@@ -239,12 +240,13 @@ class TestMissedHuddleMessageEmailMessages(ZulipTestCase):
class TestMissedMessageAddressWithEmptyGateway(ZulipTestCase): class TestMissedMessageAddressWithEmptyGateway(ZulipTestCase):
def test_address_with_empty_gateway(self): def test_address_with_empty_gateway(self):
# type: () -> None # type: () -> None
self.login("othello@zulip.com") email = self.example_email('othello')
self.login(email)
result = self.client_post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": ujson.dumps(["cordelia@zulip.com", "to": ujson.dumps([self.example_email('cordelia'),
"iago@zulip.com"])}) self.example_email('iago')])})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = self.example_user('cordelia') user_profile = self.example_user('cordelia')
@@ -263,11 +265,12 @@ class TestDigestEmailMessages(ZulipTestCase):
# build dummy messages for missed messages email reply # build dummy messages for missed messages email reply
# have Hamlet send Othello a PM. Othello will reply via email # have Hamlet send Othello a PM. Othello will reply via email
# Hamlet will receive the message. # Hamlet will receive the message.
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
result = self.client_post("/json/messages", {"type": "private", result = self.client_post("/json/messages", {"type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": "othello@zulip.com"}) "to": self.example_email('othello')})
self.assert_json_success(result) self.assert_json_success(result)
user_profile = self.example_user('othello') user_profile = self.example_user('othello')
@@ -275,7 +278,7 @@ class TestDigestEmailMessages(ZulipTestCase):
handle_digest_email(user_profile.id, cutoff) handle_digest_email(user_profile.id, cutoff)
self.assertEqual(mock_send_future_email.call_count, 1) self.assertEqual(mock_send_future_email.call_count, 1)
self.assertEqual(mock_send_future_email.call_args[0][1], u'othello@zulip.com') self.assertEqual(mock_send_future_email.call_args[0][1], self.example_email('othello'))
class TestReplyExtraction(ZulipTestCase): class TestReplyExtraction(ZulipTestCase):
def test_reply_is_extracted_from_plain(self): def test_reply_is_extracted_from_plain(self):
@@ -283,7 +286,8 @@ 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") email = self.example_email('hamlet')
self.login(email)
user_profile = self.example_user('hamlet') 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)
@@ -298,9 +302,9 @@ class TestReplyExtraction(ZulipTestCase):
incoming_valid_message = MIMEText(text) # type: Any # https://github.com/python/typeshed/issues/275 incoming_valid_message = MIMEText(text) # type: Any # https://github.com/python/typeshed/issues/275
incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject' incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject'
incoming_valid_message['From'] = "hamlet@zulip.com" incoming_valid_message['From'] = self.example_email('hamlet')
incoming_valid_message['To'] = stream_to_address incoming_valid_message['To'] = stream_to_address
incoming_valid_message['Reply-to'] = "othello@zulip.com" incoming_valid_message['Reply-to'] = self.example_email('othello')
process_message(incoming_valid_message) process_message(incoming_valid_message)
@@ -314,7 +318,8 @@ 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") email = self.example_email('hamlet')
self.login(email)
user_profile = self.example_user('hamlet') 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)
@@ -342,9 +347,9 @@ class TestReplyExtraction(ZulipTestCase):
incoming_valid_message = MIMEText(html, 'html') # type: Any # https://github.com/python/typeshed/issues/275 incoming_valid_message = MIMEText(html, 'html') # type: Any # https://github.com/python/typeshed/issues/275
incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject' incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject'
incoming_valid_message['From'] = "hamlet@zulip.com" incoming_valid_message['From'] = self.example_email('hamlet')
incoming_valid_message['To'] = stream_to_address incoming_valid_message['To'] = stream_to_address
incoming_valid_message['Reply-to'] = "othello@zulip.com" incoming_valid_message['Reply-to'] = self.example_email('othello')
process_message(incoming_valid_message) process_message(incoming_valid_message)
@@ -356,14 +361,14 @@ class TestReplyExtraction(ZulipTestCase):
MAILS_DIR = os.path.join(dirname(dirname(abspath(__file__))), "fixtures", "email") MAILS_DIR = os.path.join(dirname(dirname(abspath(__file__))), "fixtures", "email")
class TestScriptMTA(TestCase): class TestScriptMTA(ZulipTestCase):
def test_success(self): def test_success(self):
# type: () -> None # type: () -> None
script = os.path.join(os.path.dirname(__file__), script = os.path.join(os.path.dirname(__file__),
'../../scripts/lib/email-mirror-postfix') '../../scripts/lib/email-mirror-postfix')
sender = "hamlet@zulip.com" sender = self.example_email('hamlet')
stream = get_stream("Denmark", get_realm("zulip")) stream = get_stream("Denmark", get_realm("zulip"))
stream_to_address = encode_email_address(stream) stream_to_address = encode_email_address(stream)
@@ -383,7 +388,7 @@ class TestScriptMTA(TestCase):
script = os.path.join(os.path.dirname(__file__), script = os.path.join(os.path.dirname(__file__),
'../../scripts/lib/email-mirror-postfix') '../../scripts/lib/email-mirror-postfix')
sender = "hamlet@zulip.com" sender = self.example_email('hamlet')
stream = get_stream("Denmark", get_realm("zulip")) stream = get_stream("Denmark", get_realm("zulip"))
stream_to_address = encode_email_address(stream) stream_to_address = encode_email_address(stream)
template_path = os.path.join(MAILS_DIR, "simple.txt") template_path = os.path.join(MAILS_DIR, "simple.txt")
@@ -411,14 +416,15 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
def send_private_message(self): def send_private_message(self):
# type: () -> Text # type: () -> Text
self.login("othello@zulip.com") email = self.example_email('othello')
self.login(email)
result = self.client_post( result = self.client_post(
"/json/messages", "/json/messages",
{ {
"type": "private", "type": "private",
"content": "test_receive_missed_message_email_messages", "content": "test_receive_missed_message_email_messages",
"client": "test suite", "client": "test suite",
"to": ujson.dumps(["cordelia@zulip.com", "iago@zulip.com"]) "to": ujson.dumps([self.example_email('cordelia'), self.example_email('iago')])
}) })
self.assert_json_success(result) self.assert_json_success(result)
@@ -454,7 +460,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
# type: () -> None # type: () -> None
stream = get_stream("Denmark", get_realm("zulip")) stream = get_stream("Denmark", get_realm("zulip"))
stream_to_address = encode_email_address(stream) stream_to_address = encode_email_address(stream)
result = self.send_offline_message(stream_to_address, "hamlet@zulip.com") result = self.send_offline_message(stream_to_address, self.example_email('hamlet'))
self.assert_json_success(result) self.assert_json_success(result)
def test_error_to_stream_with_wrong_address(self): def test_error_to_stream_with_wrong_address(self):
@@ -463,7 +469,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
stream_to_address = encode_email_address(stream) stream_to_address = encode_email_address(stream)
stream_to_address = stream_to_address.replace("Denmark", "Wrong_stream") stream_to_address = stream_to_address.replace("Denmark", "Wrong_stream")
result = self.send_offline_message(stream_to_address, "hamlet@zulip.com") result = self.send_offline_message(stream_to_address, self.example_email('hamlet'))
self.assert_json_error( self.assert_json_error(
result, result,
"5.1.1 Bad destination mailbox address: " "5.1.1 Bad destination mailbox address: "
@@ -472,14 +478,14 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
def test_success_to_private(self): def test_success_to_private(self):
# type: () -> None # type: () -> None
mm_address = self.send_private_message() mm_address = self.send_private_message()
result = self.send_offline_message(mm_address, "cordelia@zulip.com") result = self.send_offline_message(mm_address, self.example_email('cordelia'))
self.assert_json_success(result) self.assert_json_success(result)
def test_using_mm_address_twice(self): def test_using_mm_address_twice(self):
# type: () -> None # type: () -> None
mm_address = self.send_private_message() mm_address = self.send_private_message()
self.send_offline_message(mm_address, "cordelia@zulip.com") self.send_offline_message(mm_address, self.example_email('cordelia'))
result = self.send_offline_message(mm_address, "cordelia@zulip.com") result = self.send_offline_message(mm_address, self.example_email('cordelia'))
self.assert_json_error( self.assert_json_error(
result, result,
"5.1.1 Bad destination mailbox address: Bad or expired missed message address.") "5.1.1 Bad destination mailbox address: Bad or expired missed message address.")
@@ -488,7 +494,7 @@ class TestEmailMirrorTornadoView(ZulipTestCase):
# type: () -> None # type: () -> None
self.send_private_message() self.send_private_message()
mm_address = 'mm' + ('x' * 32) + '@testserver' mm_address = 'mm' + ('x' * 32) + '@testserver'
result = self.send_offline_message(mm_address, "cordelia@zulip.com") result = self.send_offline_message(mm_address, self.example_email('cordelia'))
self.assert_json_error( self.assert_json_error(
result, result,
"5.1.1 Bad destination mailbox address: Bad or expired missed message address.") "5.1.1 Bad destination mailbox address: Bad or expired missed message address.")

View File

@@ -50,9 +50,11 @@ def rm_tree(path):
class QueryUtilTest(ZulipTestCase): class QueryUtilTest(ZulipTestCase):
def _create_messages(self): def _create_messages(self):
# type: () -> None # type: () -> None
for email in ['cordelia@zulip.com', 'hamlet@zulip.com', 'iago@zulip.com']: for email in [self.example_email('cordelia'),
self.example_email('hamlet'),
self.example_email('iago')]:
for _ in range(5): for _ in range(5):
self.send_message(email, 'othello@zulip.com', Recipient.PERSONAL) self.send_message(email, self.example_email('othello'), Recipient.PERSONAL)
@slow('creates lots of data') @slow('creates lots of data')
def test_query_chunker(self): def test_query_chunker(self):
@@ -266,7 +268,7 @@ class ExportTest(ZulipTestCase):
if r['id'] == db_id][0] if r['id'] == db_id][0]
exported_user_emails = get_set('zerver_userprofile', 'email') exported_user_emails = get_set('zerver_userprofile', 'email')
self.assertIn('cordelia@zulip.com', exported_user_emails) self.assertIn(self.example_email('cordelia'), exported_user_emails)
self.assertIn('default-bot@zulip.com', exported_user_emails) self.assertIn('default-bot@zulip.com', exported_user_emails)
self.assertIn('emailgateway@zulip.com', exported_user_emails) self.assertIn('emailgateway@zulip.com', exported_user_emails)
@@ -295,11 +297,11 @@ class ExportTest(ZulipTestCase):
full_data = self._export_realm(realm, exportable_user_ids=user_ids) full_data = self._export_realm(realm, exportable_user_ids=user_ids)
data = full_data['realm'] data = full_data['realm']
exported_user_emails = get_set('zerver_userprofile', 'email') exported_user_emails = get_set('zerver_userprofile', 'email')
self.assertIn('cordelia@zulip.com', exported_user_emails) self.assertIn(self.example_email('cordelia'), exported_user_emails)
self.assertIn('hamlet@zulip.com', exported_user_emails) self.assertIn(self.example_email('hamlet'), exported_user_emails)
self.assertNotIn('default-bot@zulip.com', exported_user_emails) self.assertNotIn('default-bot@zulip.com', exported_user_emails)
self.assertNotIn('iago@zulip.com', exported_user_emails) self.assertNotIn(self.example_email('iago'), exported_user_emails)
dummy_user_emails = get_set('zerver_userprofile_mirrordummy', 'email') dummy_user_emails = get_set('zerver_userprofile_mirrordummy', 'email')
self.assertIn('iago@zulip.com', dummy_user_emails) self.assertIn(self.example_email('iago'), dummy_user_emails)
self.assertNotIn('cordelia@zulip.com', dummy_user_emails) self.assertNotIn(self.example_email('cordelia'), dummy_user_emails)

View File

@@ -15,19 +15,19 @@ import ujson
class TestGetNextHotspots(ZulipTestCase): class TestGetNextHotspots(ZulipTestCase):
def test_first_hotspot(self): def test_first_hotspot(self):
# type: () -> None # type: () -> None
user = UserProfile.objects.get(email='hamlet@zulip.com') user = self.example_user('hamlet')
self.assertEqual(get_next_hotspots(user), ['welcome']) self.assertEqual(get_next_hotspots(user), ['welcome'])
def test_some_done_some_not(self): def test_some_done_some_not(self):
# type: () -> None # type: () -> None
user = UserProfile.objects.get(email='hamlet@zulip.com') user = self.example_user('hamlet')
do_mark_hotspot_as_read(user, 'welcome') do_mark_hotspot_as_read(user, 'welcome')
do_mark_hotspot_as_read(user, 'topics') do_mark_hotspot_as_read(user, 'topics')
self.assertEqual(get_next_hotspots(user), ['streams']) self.assertEqual(get_next_hotspots(user), ['streams'])
def test_all_done(self): def test_all_done(self):
# type: () -> None # type: () -> None
user = UserProfile.objects.get(email='hamlet@zulip.com') user = self.example_user('hamlet')
for hotspot in ALL_HOTSPOTS: for hotspot in ALL_HOTSPOTS:
do_mark_hotspot_as_read(user, hotspot) do_mark_hotspot_as_read(user, hotspot)
self.assertEqual(get_next_hotspots(user), []) self.assertEqual(get_next_hotspots(user), [])
@@ -35,16 +35,15 @@ class TestGetNextHotspots(ZulipTestCase):
class TestHotspots(ZulipTestCase): class TestHotspots(ZulipTestCase):
def test_do_mark_hotspot_as_read(self): def test_do_mark_hotspot_as_read(self):
# type: () -> None # type: () -> None
user = UserProfile.objects.get(email='hamlet@zulip.com') user = self.example_user('hamlet')
do_mark_hotspot_as_read(user, 'streams') do_mark_hotspot_as_read(user, 'streams')
self.assertEqual(list(UserHotspot.objects.filter(user=user) self.assertEqual(list(UserHotspot.objects.filter(user=user)
.values_list('hotspot', flat=True)), ['streams']) .values_list('hotspot', flat=True)), ['streams'])
def test_hotspots_url_endpoint(self): def test_hotspots_url_endpoint(self):
# type: () -> None # type: () -> None
email = 'hamlet@zulip.com' user = self.example_user('hamlet')
user = UserProfile.objects.get(email=email) self.login(user.email)
self.login(email)
result = self.client_post('/json/users/me/hotspots', result = self.client_post('/json/users/me/hotspots',
{'hotspot': ujson.dumps('welcome')}) {'hotspot': ujson.dumps('welcome')})
self.assert_json_success(result) self.assert_json_success(result)

View File

@@ -80,7 +80,8 @@ class JsonTranslationTestCase(ZulipTestCase):
dummy_value = "Some other language '%s'" dummy_value = "Some other language '%s'"
mock_gettext.return_value = dummy_value mock_gettext.return_value = dummy_value
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
result = self.client_post("/json/refer_friend", result = self.client_post("/json/refer_friend",
HTTP_ACCEPT_LANGUAGE='de') HTTP_ACCEPT_LANGUAGE='de')
@@ -94,7 +95,8 @@ class JsonTranslationTestCase(ZulipTestCase):
dummy_value = "Some other language" dummy_value = "Some other language"
mock_gettext.return_value = dummy_value mock_gettext.return_value = dummy_value
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
result = self.client_get("/de/accounts/login/jwt/") result = self.client_get("/de/accounts/login/jwt/")
self.assert_json_error_contains(result, self.assert_json_error_contains(result,

View File

@@ -173,8 +173,9 @@ class PreviewTestCase(ZulipTestCase):
@override_settings(INLINE_URL_EMBED_PREVIEW=True) @override_settings(INLINE_URL_EMBED_PREVIEW=True)
def test_edit_message_history(self): def test_edit_message_history(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
msg_id = self.send_message("hamlet@zulip.com", "Scotland", Recipient.STREAM, self.login(email)
msg_id = self.send_message(email, "Scotland", Recipient.STREAM,
subject="editing", content="original") subject="editing", content="original")
url = 'http://test.org/' url = 'http://test.org/'
@@ -206,7 +207,7 @@ class PreviewTestCase(ZulipTestCase):
url = 'http://test.org/' url = 'http://test.org/'
with mock.patch('zerver.lib.actions.queue_json_publish') as patched: with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
msg_id = self.send_message( msg_id = self.send_message(
sender_email, "cordelia@zulip.com", sender_email, self.example_email('cordelia'),
Recipient.PERSONAL, subject="url", content=url) Recipient.PERSONAL, subject="url", content=url)
if queue_should_run: if queue_should_run:
patched.assert_called_once() patched.assert_called_once()
@@ -245,7 +246,7 @@ class PreviewTestCase(ZulipTestCase):
embedded_link = '<a href="{0}" target="_blank" title="The Rock">The Rock</a>'.format(url) embedded_link = '<a href="{0}" target="_blank" title="The Rock">The Rock</a>'.format(url)
# When humans send, we should get embedded content. # When humans send, we should get embedded content.
msg = self._send_message_with_test_org_url(sender_email='hamlet@zulip.com') msg = self._send_message_with_test_org_url(sender_email=self.example_email('hamlet'))
self.assertIn(embedded_link, msg.rendered_content) self.assertIn(embedded_link, msg.rendered_content)
# We don't want embedded content for bots. # We don't want embedded content for bots.
@@ -255,35 +256,35 @@ class PreviewTestCase(ZulipTestCase):
# Try another human to make sure bot failure was due to the # Try another human to make sure bot failure was due to the
# bot sending the message and not some other reason. # bot sending the message and not some other reason.
msg = self._send_message_with_test_org_url(sender_email='prospero@zulip.com') msg = self._send_message_with_test_org_url(sender_email=self.example_email('prospero'))
self.assertIn(embedded_link, msg.rendered_content) self.assertIn(embedded_link, msg.rendered_content)
def test_inline_url_embed_preview(self): def test_inline_url_embed_preview(self):
# type: () -> None # type: () -> None
with_preview = '<p><a href="http://test.org/" target="_blank" title="http://test.org/">http://test.org/</a></p>\n<div class="message_embed"><a class="message_embed_image" href="http://test.org/" style="background-image: url(http://ia.media-imdb.com/images/rock.jpg)" target="_blank"></a><div class="data-container"><div class="message_embed_title"><a href="http://test.org/" target="_blank" title="The Rock">The Rock</a></div><div class="message_embed_description">Description text</div></div></div>' with_preview = '<p><a href="http://test.org/" target="_blank" title="http://test.org/">http://test.org/</a></p>\n<div class="message_embed"><a class="message_embed_image" href="http://test.org/" style="background-image: url(http://ia.media-imdb.com/images/rock.jpg)" target="_blank"></a><div class="data-container"><div class="message_embed_title"><a href="http://test.org/" target="_blank" title="The Rock">The Rock</a></div><div class="message_embed_description">Description text</div></div></div>'
without_preview = '<p><a href="http://test.org/" target="_blank" title="http://test.org/">http://test.org/</a></p>' without_preview = '<p><a href="http://test.org/" target="_blank" title="http://test.org/">http://test.org/</a></p>'
msg = self._send_message_with_test_org_url(sender_email='hamlet@zulip.com') msg = self._send_message_with_test_org_url(sender_email=self.example_email('hamlet'))
self.assertEqual(msg.rendered_content, with_preview) self.assertEqual(msg.rendered_content, with_preview)
realm = msg.get_realm() realm = msg.get_realm()
setattr(realm, 'inline_url_embed_preview', False) setattr(realm, 'inline_url_embed_preview', False)
realm.save() realm.save()
msg = self._send_message_with_test_org_url(sender_email='prospero@zulip.com', queue_should_run=False) msg = self._send_message_with_test_org_url(sender_email=self.example_email('prospero'), queue_should_run=False)
self.assertEqual(msg.rendered_content, without_preview) self.assertEqual(msg.rendered_content, without_preview)
def test_inline_url_embed_preview_with_relative_image_url(self): def test_inline_url_embed_preview_with_relative_image_url(self):
# type: () -> None # type: () -> None
with_preview_relative = '<p><a href="http://test.org/" target="_blank" title="http://test.org/">http://test.org/</a></p>\n<div class="message_embed"><a class="message_embed_image" href="http://test.org/" style="background-image: url(http://test.org/images/rock.jpg)" target="_blank"></a><div class="data-container"><div class="message_embed_title"><a href="http://test.org/" target="_blank" title="The Rock">The Rock</a></div><div class="message_embed_description">Description text</div></div></div>' with_preview_relative = '<p><a href="http://test.org/" target="_blank" title="http://test.org/">http://test.org/</a></p>\n<div class="message_embed"><a class="message_embed_image" href="http://test.org/" style="background-image: url(http://test.org/images/rock.jpg)" target="_blank"></a><div class="data-container"><div class="message_embed_title"><a href="http://test.org/" target="_blank" title="The Rock">The Rock</a></div><div class="message_embed_description">Description text</div></div></div>'
# Try case where the opengraph image is a relative url. # Try case where the opengraph image is a relative url.
msg = self._send_message_with_test_org_url(sender_email='prospero@zulip.com', relative_url=True) msg = self._send_message_with_test_org_url(sender_email=self.example_email('prospero'), relative_url=True)
self.assertEqual(msg.rendered_content, with_preview_relative) self.assertEqual(msg.rendered_content, with_preview_relative)
def test_http_error_get_data(self): def test_http_error_get_data(self):
# type: () -> None # type: () -> None
url = 'http://test.org/' url = 'http://test.org/'
msg_id = self.send_message( msg_id = self.send_message(
"hamlet@zulip.com", "cordelia@zulip.com", self.example_email('hamlet'), self.example_email('cordelia'),
Recipient.PERSONAL, subject="url", content=url) Recipient.PERSONAL, subject="url", content=url)
msg = Message.objects.select_related("sender").get(id=msg_id) msg = Message.objects.select_related("sender").get(id=msg_id)
event = { event = {

View File

@@ -95,7 +95,8 @@ class AdminZulipHandlerTest(ZulipTestCase):
# type: () -> None # type: () -> None
"""A request with with no stack where report.getMessage() has newlines """A request with with no stack where report.getMessage() has newlines
in it is handled properly""" in it is handled properly"""
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
with patch("zerver.decorator.rate_limit") as rate_limit_patch: with patch("zerver.decorator.rate_limit") as rate_limit_patch:
rate_limit_patch.side_effect = capture_and_throw rate_limit_patch.side_effect = capture_and_throw
result = self.client_get("/json/users") result = self.client_get("/json/users")
@@ -119,7 +120,8 @@ class AdminZulipHandlerTest(ZulipTestCase):
def test_request(self): def test_request(self):
# type: () -> None # type: () -> None
"""A normal request is handled properly""" """A normal request is handled properly"""
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
with patch("zerver.decorator.rate_limit") as rate_limit_patch: with patch("zerver.decorator.rate_limit") as rate_limit_patch:
rate_limit_patch.side_effect = capture_and_throw rate_limit_patch.side_effect = capture_and_throw
result = self.client_get("/json/users") result = self.client_get("/json/users")

View File

@@ -21,7 +21,8 @@ class SendLoginEmailTest(ZulipTestCase):
# type: () -> None # type: () -> None
with self.settings(SEND_LOGIN_EMAILS=True): with self.settings(SEND_LOGIN_EMAILS=True):
self.assertTrue(settings.SEND_LOGIN_EMAILS) self.assertTrue(settings.SEND_LOGIN_EMAILS)
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
# email is sent and correct subject # email is sent and correct subject
self.assertEqual(len(mail.outbox), 1) self.assertEqual(len(mail.outbox), 1)
@@ -30,7 +31,8 @@ class SendLoginEmailTest(ZulipTestCase):
def test_dont_send_login_emails_if_send_login_emails_is_false(self): def test_dont_send_login_emails_if_send_login_emails_is_false(self):
# type: () -> None # type: () -> None
self.assertFalse(settings.SEND_LOGIN_EMAILS) self.assertFalse(settings.SEND_LOGIN_EMAILS)
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
self.assertEqual(len(mail.outbox), 0) self.assertEqual(len(mail.outbox), 0)

View File

@@ -61,9 +61,9 @@ class TestMissedMessages(ZulipTestCase):
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
for i in range(0, 11): for i in range(0, 11):
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, str(i)) self.send_message(self.example_email('othello'), "Denmark", Recipient.STREAM, str(i))
self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '11', subject='test2') self.send_message(self.example_email('othello'), "Denmark", Recipient.STREAM, '11', subject='test2')
msg_id = self.send_message("othello@zulip.com", "denmark", Recipient.STREAM, '@**hamlet**') msg_id = self.send_message(self.example_email('othello'), "denmark", Recipient.STREAM, '@**hamlet**')
body = 'Denmark > test Othello, the Moor of Venice 1 2 3 4 5 6 7 8 9 10 @**hamlet**' body = 'Denmark > test Othello, the Moor of Venice 1 2 3 4 5 6 7 8 9 10 @**hamlet**'
subject = 'Othello, the Moor of Venice mentioned you in Zulip Dev' subject = 'Othello, the Moor of Venice mentioned you in Zulip Dev'
self._test_cases(tokens, msg_id, body, subject, send_as_user) self._test_cases(tokens, msg_id, body, subject, send_as_user)
@@ -75,8 +75,8 @@ class TestMissedMessages(ZulipTestCase):
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
for i in range(0, 3): for i in range(0, 3):
self.send_message("cordelia@zulip.com", "Denmark", Recipient.STREAM, str(i)) self.send_message(self.example_email('cordelia'), "Denmark", Recipient.STREAM, str(i))
msg_id = self.send_message("othello@zulip.com", "Denmark", Recipient.STREAM, '@**hamlet**') msg_id = self.send_message(self.example_email('othello'), "Denmark", Recipient.STREAM, '@**hamlet**')
body = 'Denmark > test Cordelia Lear 0 1 2 Othello, the Moor of Venice @**hamlet**' body = 'Denmark > test Cordelia Lear 0 1 2 Othello, the Moor of Venice @**hamlet**'
subject = 'Othello, the Moor of Venice mentioned you in Zulip Dev' subject = 'Othello, the Moor of Venice mentioned you in Zulip Dev'
self._test_cases(tokens, msg_id, body, subject, send_as_user) self._test_cases(tokens, msg_id, body, subject, send_as_user)
@@ -87,7 +87,7 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com", msg_id = self.send_message(self.example_email('othello'), self.example_email('hamlet'),
Recipient.PERSONAL, Recipient.PERSONAL,
'Extremely personal message!') 'Extremely personal message!')
body = 'You and Othello, the Moor of Venice Extremely personal message!' body = 'You and Othello, the Moor of Venice Extremely personal message!'
@@ -100,7 +100,7 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com", msg_id = self.send_message(self.example_email('othello'), self.example_email('hamlet'),
Recipient.PERSONAL, Recipient.PERSONAL,
'Extremely personal message!') 'Extremely personal message!')
body = 'Or just reply to this email.' body = 'Or just reply to this email.'
@@ -113,7 +113,7 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com", msg_id = self.send_message(self.example_email('othello'), self.example_email('hamlet'),
Recipient.PERSONAL, Recipient.PERSONAL,
'Extremely personal message!') 'Extremely personal message!')
body = 'Please do not reply to this automated message.' body = 'Please do not reply to this automated message.'
@@ -126,8 +126,8 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", msg_id = self.send_message(self.example_email('othello'),
["hamlet@zulip.com", "iago@zulip.com"], [self.example_email('hamlet'), self.example_email('iago')],
Recipient.HUDDLE, Recipient.HUDDLE,
'Group personal message!') 'Group personal message!')
@@ -142,8 +142,8 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", msg_id = self.send_message(self.example_email('othello'),
["hamlet@zulip.com", "iago@zulip.com", "cordelia@zulip.com"], [self.example_email('hamlet'), self.example_email('iago'), self.example_email('cordelia')],
Recipient.HUDDLE, Recipient.HUDDLE,
'Group personal message!') 'Group personal message!')
@@ -158,8 +158,11 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", msg_id = self.send_message(self.example_email('othello'),
["hamlet@zulip.com", "iago@zulip.com", "cordelia@zulip.com", "prospero@zulip.com"], [self.example_email('hamlet'),
self.example_email('iago'),
self.example_email('cordelia'),
self.example_email('prospero')],
Recipient.HUDDLE, Recipient.HUDDLE,
'Group personal message!') 'Group personal message!')
@@ -174,11 +177,12 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "denmark", Recipient.STREAM, msg_id = self.send_message(self.example_email('othello'), "denmark", Recipient.STREAM,
'@**hamlet** to be deleted') '@**hamlet** to be deleted')
hamlet = self.example_user('hamlet') hamlet = self.example_user('hamlet')
self.login("othello@zulip.com") email = self.example_email('othello')
self.login(email)
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': ' '})
self.assert_json_success(result) self.assert_json_success(result)
@@ -191,11 +195,14 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", "hamlet@zulip.com", Recipient.PERSONAL, msg_id = self.send_message(self.example_email('othello'),
self.example_email('hamlet'),
Recipient.PERSONAL,
'Extremely personal message! to be deleted!') 'Extremely personal message! to be deleted!')
hamlet = self.example_user('hamlet') hamlet = self.example_user('hamlet')
self.login("othello@zulip.com") email = self.example_email('othello')
self.login(email)
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': ' '})
self.assert_json_success(result) self.assert_json_success(result)
@@ -208,12 +215,15 @@ class TestMissedMessages(ZulipTestCase):
tokens = self._get_tokens() tokens = self._get_tokens()
mock_random_token.side_effect = tokens mock_random_token.side_effect = tokens
msg_id = self.send_message("othello@zulip.com", ["hamlet@zulip.com", "iago@zulip.com"], msg_id = self.send_message(self.example_email('othello'),
[self.example_email('hamlet'),
self.example_email('iago')],
Recipient.PERSONAL, 'Group personal message!') Recipient.PERSONAL, 'Group personal message!')
hamlet = self.example_user('hamlet') hamlet = self.example_user('hamlet')
iago = self.example_user('iago') iago = self.example_user('iago')
self.login("othello@zulip.com") email = self.example_email('othello')
self.login(email)
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': ' '})
self.assert_json_success(result) self.assert_json_success(result)

View File

@@ -40,17 +40,17 @@ class WorkerTest(ZulipTestCase):
dict( dict(
message=u'\xf3test', message=u'\xf3test',
time=time.time(), time=time.time(),
rcpt_to='hamlet@zulip.com', rcpt_to=self.example_email('hamlet'),
), ),
dict( dict(
message='\xf3test', message='\xf3test',
time=time.time(), time=time.time(),
rcpt_to='hamlet@zulip.com', rcpt_to=self.example_email('hamlet'),
), ),
dict( dict(
message='test', message='test',
time=time.time(), time=time.time(),
rcpt_to='hamlet@zulip.com', rcpt_to=self.example_email('hamlet'),
), ),
] ]
for element in data: for element in data:

View File

@@ -11,7 +11,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_list(self): def test_list(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
check_add_realm_emoji(realm, "my_emoji", "my_emoji") check_add_realm_emoji(realm, "my_emoji", "my_emoji")
result = self.client_get("/json/realm/emoji") result = self.client_get("/json/realm/emoji")
@@ -22,7 +23,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_list_no_author(self): def test_list_no_author(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
RealmEmoji.objects.create(realm=realm, name='my_emojy', file_name='my_emojy') RealmEmoji.objects.create(realm=realm, name='my_emojy', file_name='my_emojy')
result = self.client_get("/json/realm/emoji") result = self.client_get("/json/realm/emoji")
@@ -33,7 +35,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_list_admins_only(self): def test_list_admins_only(self):
# type: () -> None # type: () -> None
self.login('othello@zulip.com') email = self.example_email('othello')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
realm.add_emoji_by_admins_only = True realm.add_emoji_by_admins_only = True
realm.save() realm.save()
@@ -46,7 +49,7 @@ class RealmEmojiTest(ZulipTestCase):
def test_upload(self): def test_upload(self):
# type: () -> None # type: () -> None
email = "iago@zulip.com" email = self.example_email('iago')
self.login(email) self.login(email)
with get_test_image_file('img.png') as fp1: with get_test_image_file('img.png') as fp1:
emoji_data = {'f1': fp1} emoji_data = {'f1': fp1}
@@ -72,7 +75,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_upload_exception(self): def test_upload_exception(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
with get_test_image_file('img.png') as fp1: with get_test_image_file('img.png') as fp1:
emoji_data = {'f1': fp1} emoji_data = {'f1': fp1}
result = self.client_put_multipart('/json/realm/emoji/my_em*oji', info=emoji_data) result = self.client_put_multipart('/json/realm/emoji/my_em*oji', info=emoji_data)
@@ -80,7 +84,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_upload_uppercase_exception(self): def test_upload_uppercase_exception(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
with get_test_image_file('img.png') as fp1: with get_test_image_file('img.png') as fp1:
emoji_data = {'f1': fp1} emoji_data = {'f1': fp1}
result = self.client_put_multipart('/json/realm/emoji/my_EMoji', info=emoji_data) result = self.client_put_multipart('/json/realm/emoji/my_EMoji', info=emoji_data)
@@ -88,7 +93,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_upload_admins_only(self): def test_upload_admins_only(self):
# type: () -> None # type: () -> None
self.login('othello@zulip.com') email = self.example_email('othello')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
realm.add_emoji_by_admins_only = True realm.add_emoji_by_admins_only = True
realm.save() realm.save()
@@ -99,7 +105,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_delete(self): def test_delete(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
check_add_realm_emoji(realm, "my_emoji", "my_emoji.png") check_add_realm_emoji(realm, "my_emoji", "my_emoji.png")
result = self.client_delete("/json/realm/emoji/my_emoji") result = self.client_delete("/json/realm/emoji/my_emoji")
@@ -112,7 +119,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_delete_admins_only(self): def test_delete_admins_only(self):
# type: () -> None # type: () -> None
self.login('othello@zulip.com') email = self.example_email('othello')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
realm.add_emoji_by_admins_only = True realm.add_emoji_by_admins_only = True
realm.save() realm.save()
@@ -122,20 +130,23 @@ class RealmEmojiTest(ZulipTestCase):
def test_delete_exception(self): def test_delete_exception(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
result = self.client_delete("/json/realm/emoji/invalid_emoji") result = self.client_delete("/json/realm/emoji/invalid_emoji")
self.assert_json_error(result, "Emoji 'invalid_emoji' does not exist") self.assert_json_error(result, "Emoji 'invalid_emoji' does not exist")
def test_multiple_upload(self): def test_multiple_upload(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
with get_test_image_file('img.png') as fp1, get_test_image_file('img.png') as fp2: with get_test_image_file('img.png') as fp1, get_test_image_file('img.png') as fp2:
result = self.client_put_multipart('/json/realm/emoji/my_emoji', {'f1': fp1, 'f2': fp2}) result = self.client_put_multipart('/json/realm/emoji/my_emoji', {'f1': fp1, 'f2': fp2})
self.assert_json_error(result, 'You must upload exactly one file.') self.assert_json_error(result, 'You must upload exactly one file.')
def test_emoji_upload_file_size_error(self): def test_emoji_upload_file_size_error(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
with get_test_image_file('img.png') as fp: with get_test_image_file('img.png') as fp:
with self.settings(MAX_EMOJI_FILE_SIZE=0): with self.settings(MAX_EMOJI_FILE_SIZE=0):
result = self.client_put_multipart('/json/realm/emoji/my_emoji', {'file': fp}) result = self.client_put_multipart('/json/realm/emoji/my_emoji', {'file': fp})
@@ -143,7 +154,8 @@ class RealmEmojiTest(ZulipTestCase):
def test_upload_already_existed_emoji(self): def test_upload_already_existed_emoji(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
with get_test_image_file('img.png') as fp1: with get_test_image_file('img.png') as fp1:
emoji_data = {'f1': fp1} emoji_data = {'f1': fp1}
self.client_put_multipart('/json/realm/emoji/my_emoji', info=emoji_data) self.client_put_multipart('/json/realm/emoji/my_emoji', info=emoji_data)

View File

@@ -11,7 +11,8 @@ class RealmFilterTest(ZulipTestCase):
def test_list(self): def test_list(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
do_add_realm_filter( do_add_realm_filter(
realm, realm,
@@ -25,7 +26,8 @@ class RealmFilterTest(ZulipTestCase):
def test_create(self): def test_create(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
data = {"pattern": "", "url_format_string": "https://realm.com/my_realm_filter/%(id)s"} data = {"pattern": "", "url_format_string": "https://realm.com/my_realm_filter/%(id)s"}
result = self.client_post("/json/realm/filters", info=data) result = self.client_post("/json/realm/filters", info=data)
self.assert_json_error(result, 'This field cannot be blank.') self.assert_json_error(result, 'This field cannot be blank.')
@@ -54,7 +56,8 @@ class RealmFilterTest(ZulipTestCase):
def test_not_realm_admin(self): def test_not_realm_admin(self):
# type: () -> None # type: () -> None
self.login("hamlet@zulip.com") email = self.example_email('hamlet')
self.login(email)
result = self.client_post("/json/realm/filters") result = self.client_post("/json/realm/filters")
self.assert_json_error(result, 'Must be a realm administrator') self.assert_json_error(result, 'Must be a realm administrator')
result = self.client_delete("/json/realm/filters/15") result = self.client_delete("/json/realm/filters/15")
@@ -62,7 +65,8 @@ class RealmFilterTest(ZulipTestCase):
def test_delete(self): def test_delete(self):
# type: () -> None # type: () -> None
self.login("iago@zulip.com") email = self.example_email('iago')
self.login(email)
realm = get_realm('zulip') realm = get_realm('zulip')
filter_id = do_add_realm_filter( filter_id = do_add_realm_filter(
realm, realm,

View File

@@ -39,7 +39,7 @@ class StatsMock(object):
class TestReport(ZulipTestCase): class TestReport(ZulipTestCase):
def test_send_time(self): def test_send_time(self):
# type: () -> None # type: () -> None
email = 'hamlet@zulip.com' email = self.example_email('hamlet')
self.login(email) self.login(email)
params = dict( params = dict(
@@ -66,7 +66,7 @@ class TestReport(ZulipTestCase):
def test_narrow_time(self): def test_narrow_time(self):
# type: () -> None # type: () -> None
email = 'hamlet@zulip.com' email = self.example_email('hamlet')
self.login(email) self.login(email)
params = dict( params = dict(
@@ -89,7 +89,7 @@ class TestReport(ZulipTestCase):
def test_unnarrow_time(self): def test_unnarrow_time(self):
# type: () -> None # type: () -> None
email = 'hamlet@zulip.com' email = self.example_email('hamlet')
self.login(email) self.login(email)
params = dict( params = dict(
@@ -111,7 +111,7 @@ class TestReport(ZulipTestCase):
@override_settings(BROWSER_ERROR_REPORTING=True) @override_settings(BROWSER_ERROR_REPORTING=True)
def test_report_error(self): def test_report_error(self):
# type: () -> None # type: () -> None
email = 'hamlet@zulip.com' email = self.example_email('hamlet')
self.login(email) self.login(email)
params = fix_params(dict( params = fix_params(dict(

View File

@@ -33,7 +33,7 @@ from zerver.tornado.views import get_events_backend
from six.moves.http_cookies import SimpleCookie from six.moves.http_cookies import SimpleCookie
from typing import Any, Callable, Dict, Generator, Optional from typing import Any, Callable, Dict, Generator, Optional, Text
class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase): class WebSocketBaseTestCase(AsyncHTTPTestCase, ZulipTestCase):
@@ -114,7 +114,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
@staticmethod @staticmethod
def _get_queue_events_data(email): def _get_queue_events_data(email):
# type: (str) -> Dict[str, Dict[str, str]] # type: (Text) -> Dict[str, Dict[str, str]]
user_profile = UserProfile.objects.filter(email=email).first() user_profile = UserProfile.objects.filter(email=email).first()
events_query = { events_query = {
'queue_id': None, 'queue_id': None,
@@ -182,7 +182,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
@gen_test @gen_test
def test_tornado_connect(self): def test_tornado_connect(self):
# type: () -> Generator[str, Any, None] # type: () -> Generator[str, Any, None]
user_profile = UserProfile.objects.filter(email='hamlet@zulip.com').first() user_profile = self.example_user('hamlet')
cookies = self._get_cookies(user_profile) cookies = self._get_cookies(user_profile)
cookie_header = self.get_cookie_header(cookies) cookie_header = self.get_cookie_header(cookies)
ws = yield self.ws_connect('/sockjs/366/v8nw22qe/websocket', cookie_header=cookie_header) ws = yield self.ws_connect('/sockjs/366/v8nw22qe/websocket', cookie_header=cookie_header)
@@ -193,7 +193,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
@gen_test @gen_test
def test_tornado_auth(self): def test_tornado_auth(self):
# type: () -> Generator[str, TornadoTestCase, None] # type: () -> Generator[str, TornadoTestCase, None]
user_profile = UserProfile.objects.filter(email='hamlet@zulip.com').first() user_profile = self.example_user('hamlet')
cookies = self._get_cookies(user_profile) cookies = self._get_cookies(user_profile)
cookie_header = self.get_cookie_header(cookies) cookie_header = self.get_cookie_header(cookies)
ws = yield self.ws_connect('/sockjs/366/v8nw22qe/websocket', cookie_header=cookie_header) ws = yield self.ws_connect('/sockjs/366/v8nw22qe/websocket', cookie_header=cookie_header)
@@ -227,7 +227,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
@gen_test @gen_test
def test_sending_private_message(self): def test_sending_private_message(self):
# type: () -> Generator[str, Any, None] # type: () -> Generator[str, Any, None]
user_profile = UserProfile.objects.filter(email='hamlet@zulip.com').first() user_profile = self.example_user('hamlet')
cookies = self._get_cookies(user_profile) cookies = self._get_cookies(user_profile)
cookie_header = self.get_cookie_header(cookies) cookie_header = self.get_cookie_header(cookies)
queue_events_data = self._get_queue_events_data(user_profile.email) queue_events_data = self._get_queue_events_data(user_profile.email)
@@ -243,12 +243,12 @@ class TornadoTestCase(WebSocketBaseTestCase):
"type": "private", "type": "private",
"subject": "(no topic)", "subject": "(no topic)",
"stream": "", "stream": "",
"private_message_recipient": "othello@zulip.com", "private_message_recipient": self.example_email('othello'),
"content": "hello", "content": "hello",
"sender_id": user_profile.id, "sender_id": user_profile.id,
"queue_id": queue_events_data['response']['queue_id'], "queue_id": queue_events_data['response']['queue_id'],
"to": ujson.dumps(["othello@zulip.com"]), "to": ujson.dumps([self.example_email('othello')]),
"reply_to": "hamlet@zulip.com", "reply_to": self.example_email('hamlet'),
"local_id": -1 "local_id": -1
} }
} }
@@ -262,7 +262,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
@gen_test @gen_test
def test_sending_stream_message(self): def test_sending_stream_message(self):
# type: () -> Generator[str, Any, None] # type: () -> Generator[str, Any, None]
user_profile = UserProfile.objects.filter(email='hamlet@zulip.com').first() user_profile = self.example_user('hamlet')
cookies = self._get_cookies(user_profile) cookies = self._get_cookies(user_profile)
cookie_header = self.get_cookie_header(cookies) cookie_header = self.get_cookie_header(cookies)
queue_events_data = self._get_queue_events_data(user_profile.email) queue_events_data = self._get_queue_events_data(user_profile.email)
@@ -283,7 +283,7 @@ class TornadoTestCase(WebSocketBaseTestCase):
"sender_id": user_profile.id, "sender_id": user_profile.id,
"queue_id": queue_events_data['response']['queue_id'], "queue_id": queue_events_data['response']['queue_id'],
"to": ujson.dumps(["Denmark"]), "to": ujson.dumps(["Denmark"]),
"reply_to": "hamlet@zulip.com", "reply_to": self.example_email('hamlet'),
"local_id": -1 "local_id": -1
} }
} }