diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index 183dfe710a..64a3160aee 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -462,39 +462,35 @@ class ZulipTestCase(TestCase):
)
return [cast(str, get_display_recipient(sub.recipient)) for sub in subs]
- def send_personal_message(self, from_email: str, to_email: str, content: str="test content",
- sender_realm: str="zulip",
+ def send_personal_message(self, from_user: UserProfile, to_user: UserProfile, content: str="test content",
sending_client_name: str="test suite") -> int:
- sender = get_user(from_email, get_realm(sender_realm))
-
- recipient_list = [to_email]
+ recipient_list = [to_user.email]
(sending_client, _) = Client.objects.get_or_create(name=sending_client_name)
return check_send_message(
- sender, sending_client, 'private', recipient_list, None,
+ from_user, sending_client, 'private', recipient_list, None,
content
)
- def send_huddle_message(self, from_email: str, to_emails: List[str], content: str="test content",
- sender_realm: str="zulip",
+ def send_huddle_message(self,
+ from_user: UserProfile,
+ to_users: List[UserProfile],
+ content: str="test content",
sending_client_name: str="test suite") -> int:
- sender = get_user(from_email, get_realm(sender_realm))
-
+ to_emails = [u.email for u in to_users]
assert(len(to_emails) >= 2)
(sending_client, _) = Client.objects.get_or_create(name=sending_client_name)
return check_send_message(
- sender, sending_client, 'private', to_emails, None,
+ from_user, sending_client, 'private', to_emails, None,
content
)
- def send_stream_message(self, sender_email: str, stream_name: str, content: str="test content",
- topic_name: str="test", sender_realm: str="zulip",
+ def send_stream_message(self, sender: UserProfile, stream_name: str, content: str="test content",
+ topic_name: str="test",
recipient_realm: Optional[Realm]=None,
sending_client_name: str="test suite") -> int:
- sender = get_user(sender_email, get_realm(sender_realm))
-
(sending_client, _) = Client.objects.get_or_create(name=sending_client_name)
return check_send_stream_message(
diff --git a/zerver/openapi/curl_param_value_generators.py b/zerver/openapi/curl_param_value_generators.py
index 4aa872ba7f..be09072db4 100644
--- a/zerver/openapi/curl_param_value_generators.py
+++ b/zerver/openapi/curl_param_value_generators.py
@@ -60,7 +60,7 @@ def patch_openapi_example_values(entry: str, params: List[Dict[str, Any]],
"/messages/{message_id}:patch", "/messages/{message_id}:delete"])
def iago_message_id() -> Dict[str, int]:
return {
- "message_id": helpers.send_stream_message(helpers.example_email("iago"), "Denmark")
+ "message_id": helpers.send_stream_message(helpers.example_user("iago"), "Denmark")
}
@openapi_param_value_generator(["/messages/flags:post"])
@@ -70,7 +70,7 @@ def update_flags_message_ids() -> Dict[str, List[int]]:
messages = []
for _ in range(3):
- messages.append(helpers.send_stream_message(helpers.example_email("iago"), stream_name))
+ messages.append(helpers.send_stream_message(helpers.example_user("iago"), stream_name))
return {
"messages": messages,
}
@@ -101,7 +101,7 @@ def get_denmark_stream_id_and_topic() -> Dict[str, Any]:
topic_name = "Tivoli Gardens"
helpers.subscribe(helpers.example_user("iago"), stream_name)
- helpers.send_stream_message(helpers.example_email("hamlet"), stream_name, topic_name=topic_name)
+ helpers.send_stream_message(helpers.example_user("hamlet"), stream_name, topic_name=topic_name)
return {
"stream_id": helpers.get_stream_id(stream_name),
@@ -136,7 +136,7 @@ def get_events() -> Dict[str, Any]:
helpers.subscribe(profile, "Verona")
client = Client.objects.create(name="curl-test-client-1")
response = do_events_register(profile, client, event_types=['message', 'realm_emoji'])
- helpers.send_stream_message(helpers.example_email("hamlet"), "Verona")
+ helpers.send_stream_message(helpers.example_user("hamlet"), "Verona")
return {
"queue_id": response["queue_id"],
"last_event_id": response["last_event_id"],
diff --git a/zerver/tests/test_alert_words.py b/zerver/tests/test_alert_words.py
index 83ac423bf8..b37d31f78c 100644
--- a/zerver/tests/test_alert_words.py
+++ b/zerver/tests/test_alert_words.py
@@ -133,7 +133,7 @@ class AlertWordTests(ZulipTestCase):
def message_does_alert(self, user_profile: UserProfile, message: str) -> bool:
"""Send a bunch of messages as othello, so Hamlet is notified"""
- self.send_stream_message(self.example_email("othello"), "Denmark", message)
+ self.send_stream_message(self.example_user("othello"), "Denmark", message)
user_message = most_recent_usermessage(user_profile)
return 'has_alert_word' in user_message.flags_list()
@@ -172,7 +172,7 @@ class AlertWordTests(ZulipTestCase):
result = self.client_post('/json/users/me/alert_words', {'alert_words': ujson.dumps(['ALERT'])})
content = 'this is an ALERT for you'
- self.send_stream_message(me_email, "Denmark", content)
+ self.send_stream_message(user_profile, "Denmark", content)
self.assert_json_success(result)
original_message = most_recent_message(user_profile)
diff --git a/zerver/tests/test_archive.py b/zerver/tests/test_archive.py
index 2bf06298f6..f1ba505c06 100644
--- a/zerver/tests/test_archive.py
+++ b/zerver/tests/test_archive.py
@@ -34,7 +34,7 @@ class GlobalPublicStreamTest(ZulipTestCase):
def send_msg_and_get_result(msg: str) -> HttpResponse:
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
msg,
'TopicGlobal'
@@ -92,7 +92,7 @@ class WebPublicTopicHistoryTest(ZulipTestCase):
test_stream = self.make_stream('Test Public Archives')
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
'Test Message',
'TopicGlobal'
@@ -110,31 +110,31 @@ class WebPublicTopicHistoryTest(ZulipTestCase):
do_change_stream_web_public(test_stream, True)
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
'Test Message 3',
topic_name='first_topic'
)
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
'Test Message',
topic_name='TopicGlobal'
)
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
'Test Message 2',
topic_name='topicglobal'
)
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
'Test Message 3',
topic_name='second_topic'
)
self.send_stream_message(
- self.example_email("iago"),
+ self.example_user("iago"),
"Test Public Archives",
'Test Message 4',
topic_name='TopicGlobal'
diff --git a/zerver/tests/test_bugdown.py b/zerver/tests/test_bugdown.py
index 6523b82eaa..d02f652407 100644
--- a/zerver/tests/test_bugdown.py
+++ b/zerver/tests/test_bugdown.py
@@ -2005,7 +2005,7 @@ class BugdownErrorTests(ZulipTestCase):
# We don't use assertRaisesRegex because it seems to not
# handle i18n properly here on some systems.
with self.assertRaises(JsonableError):
- self.send_stream_message(self.example_email("othello"), "Denmark", message)
+ self.send_stream_message(self.example_user("othello"), "Denmark", message)
def test_ultra_long_rendering(self) -> None:
"""A rendered message with an ultra-long lenght (> 10 * MAX_MESSAGE_LENGTH)
diff --git a/zerver/tests/test_digest.py b/zerver/tests/test_digest.py
index e183ab76f0..1af70f91d2 100644
--- a/zerver/tests/test_digest.py
+++ b/zerver/tests/test_digest.py
@@ -271,9 +271,9 @@ class TestDigestEmailMessages(ZulipTestCase):
sending_client = get_client(client)
message_ids = [] # List[int]
for sender_name in senders:
- email = self.example_email(sender_name)
- content = 'some content for {} from {}'.format(stream, email)
- message_id = self.send_stream_message(email, stream, content)
+ sender = self.example_user(sender_name)
+ content = 'some content for {} from {}'.format(stream, sender_name)
+ message_id = self.send_stream_message(sender, stream, content)
message_ids.append(message_id)
Message.objects.filter(id__in=message_ids).update(sending_client=sending_client)
return message_ids
diff --git a/zerver/tests/test_email_notifications.py b/zerver/tests/test_email_notifications.py
index 014103ad24..c435948d83 100644
--- a/zerver/tests/test_email_notifications.py
+++ b/zerver/tests/test_email_notifications.py
@@ -173,8 +173,8 @@ class TestMissedMessages(ZulipTestCase):
def _realm_name_in_missed_message_email_subject(self, realm_name_in_notifications: bool) -> None:
msg_id = self.send_personal_message(
- self.example_email('othello'),
- self.example_email('hamlet'),
+ self.example_user('othello'),
+ self.example_user('hamlet'),
'Extremely personal message!',
)
verify_body_include = ['Extremely personal message!']
@@ -187,12 +187,12 @@ class TestMissedMessages(ZulipTestCase):
def _extra_context_in_missed_stream_messages_mention(self, send_as_user: bool,
show_message_content: bool=True) -> None:
for i in range(0, 11):
- self.send_stream_message(self.example_email('othello'), "Denmark", content=str(i))
+ self.send_stream_message(self.example_user('othello'), "Denmark", content=str(i))
self.send_stream_message(
- self.example_email('othello'), "Denmark",
+ self.example_user('othello'), "Denmark",
'11', topic_name='test2')
msg_id = self.send_stream_message(
- self.example_email('othello'), "denmark",
+ self.example_user('othello'), "denmark",
'@**King Hamlet**')
if show_message_content:
@@ -223,12 +223,12 @@ class TestMissedMessages(ZulipTestCase):
def _extra_context_in_missed_stream_messages_wildcard_mention(self, send_as_user: bool,
show_message_content: bool=True) -> None:
for i in range(1, 6):
- self.send_stream_message(self.example_email('othello'), "Denmark", content=str(i))
+ self.send_stream_message(self.example_user('othello'), "Denmark", content=str(i))
self.send_stream_message(
- self.example_email('othello'), "Denmark",
+ self.example_user('othello'), "Denmark",
'11', topic_name='test2')
msg_id = self.send_stream_message(
- self.example_email('othello'), "denmark",
+ self.example_user('othello'), "denmark",
'@**all**')
if show_message_content:
@@ -257,12 +257,12 @@ class TestMissedMessages(ZulipTestCase):
def _extra_context_in_missed_stream_messages_email_notify(self, send_as_user: bool) -> None:
for i in range(0, 11):
- self.send_stream_message(self.example_email('othello'), "Denmark", content=str(i))
+ self.send_stream_message(self.example_user('othello'), "Denmark", content=str(i))
self.send_stream_message(
- self.example_email('othello'), "Denmark",
+ self.example_user('othello'), "Denmark",
'11', topic_name='test2')
msg_id = self.send_stream_message(
- self.example_email('othello'), "denmark",
+ self.example_user('othello'), "denmark",
'12')
verify_body_include = [
"Othello, the Moor of Venice: 1 2 3 4 5 6 7 8 9 10 12 -- ",
@@ -273,9 +273,9 @@ class TestMissedMessages(ZulipTestCase):
def _extra_context_in_missed_stream_messages_mention_two_senders(self, send_as_user: bool) -> None:
for i in range(0, 3):
- self.send_stream_message(self.example_email('cordelia'), "Denmark", str(i))
+ self.send_stream_message(self.example_user('cordelia'), "Denmark", str(i))
msg_id = self.send_stream_message(
- self.example_email('othello'), "Denmark",
+ self.example_user('othello'), "Denmark",
'@**King Hamlet**')
verify_body_include = [
"Cordelia Lear: 0 1 2 Othello, the Moor of Venice: @**King Hamlet** -- ",
@@ -289,8 +289,8 @@ class TestMissedMessages(ZulipTestCase):
message_content_disabled_by_user: bool=False,
message_content_disabled_by_realm: bool=False) -> None:
msg_id = self.send_personal_message(
- self.example_email('othello'),
- self.example_email('hamlet'),
+ self.example_user('othello'),
+ self.example_user('hamlet'),
'Extremely personal message!',
)
@@ -322,8 +322,8 @@ class TestMissedMessages(ZulipTestCase):
def _reply_to_email_in_personal_missed_stream_messages(self, send_as_user: bool) -> None:
msg_id = self.send_personal_message(
- self.example_email('othello'),
- self.example_email('hamlet'),
+ self.example_user('othello'),
+ self.example_user('hamlet'),
'Extremely personal message!',
)
verify_body_include = ['Reply to this email directly, or view it in Zulip']
@@ -332,8 +332,8 @@ class TestMissedMessages(ZulipTestCase):
def _reply_warning_in_personal_missed_stream_messages(self, send_as_user: bool) -> None:
msg_id = self.send_personal_message(
- self.example_email('othello'),
- self.example_email('hamlet'),
+ self.example_user('othello'),
+ self.example_user('hamlet'),
'Extremely personal message!',
)
verify_body_include = ['Do not reply to this email.']
@@ -343,10 +343,10 @@ class TestMissedMessages(ZulipTestCase):
def _extra_context_in_huddle_missed_stream_messages_two_others(self, send_as_user: bool,
show_message_content: bool=True) -> None:
msg_id = self.send_huddle_message(
- self.example_email('othello'),
+ self.example_user('othello'),
[
- self.example_email('hamlet'),
- self.example_email('iago'),
+ self.example_user('hamlet'),
+ self.example_user('iago'),
],
'Group personal message!',
)
@@ -372,11 +372,11 @@ class TestMissedMessages(ZulipTestCase):
def _extra_context_in_huddle_missed_stream_messages_three_others(self, send_as_user: bool) -> None:
msg_id = self.send_huddle_message(
- self.example_email('othello'),
+ self.example_user('othello'),
[
- self.example_email('hamlet'),
- self.example_email('iago'),
- self.example_email('cordelia'),
+ self.example_user('hamlet'),
+ self.example_user('iago'),
+ self.example_user('cordelia'),
],
'Group personal message!',
)
@@ -386,11 +386,11 @@ class TestMissedMessages(ZulipTestCase):
self._test_cases(msg_id, verify_body_include, email_subject, send_as_user)
def _extra_context_in_huddle_missed_stream_messages_many_others(self, send_as_user: bool) -> None:
- msg_id = self.send_huddle_message(self.example_email('othello'),
- [self.example_email('hamlet'),
- self.example_email('iago'),
- self.example_email('cordelia'),
- self.example_email('prospero')],
+ msg_id = self.send_huddle_message(self.example_user('othello'),
+ [self.example_user('hamlet'),
+ self.example_user('iago'),
+ self.example_user('cordelia'),
+ self.example_user('prospero')],
'Group personal message!')
verify_body_include = ['Othello, the Moor of Venice: Group personal message! -- Reply']
@@ -399,7 +399,7 @@ class TestMissedMessages(ZulipTestCase):
def _deleted_message_in_missed_stream_messages(self, send_as_user: bool) -> None:
msg_id = self.send_stream_message(
- self.example_email('othello'), "denmark",
+ self.example_user('othello'), "denmark",
'@**King Hamlet** to be deleted')
hamlet = self.example_user('hamlet')
@@ -412,8 +412,8 @@ class TestMissedMessages(ZulipTestCase):
self.assertEqual(len(mail.outbox), 0)
def _deleted_message_in_personal_missed_stream_messages(self, send_as_user: bool) -> None:
- msg_id = self.send_personal_message(self.example_email('othello'),
- self.example_email('hamlet'),
+ msg_id = self.send_personal_message(self.example_user('othello'),
+ self.example_user('hamlet'),
'Extremely personal message! to be deleted!')
hamlet = self.example_user('hamlet')
@@ -427,10 +427,10 @@ class TestMissedMessages(ZulipTestCase):
def _deleted_message_in_huddle_missed_stream_messages(self, send_as_user: bool) -> None:
msg_id = self.send_huddle_message(
- self.example_email('othello'),
+ self.example_user('othello'),
[
- self.example_email('hamlet'),
- self.example_email('iago'),
+ self.example_user('hamlet'),
+ self.example_user('iago'),
],
'Group personal message!',
)
@@ -597,7 +597,7 @@ class TestMissedMessages(ZulipTestCase):
realm = get_realm("zulip")
msg_id = self.send_personal_message(
- self.example_email('othello'), self.example_email('hamlet'),
+ self.example_user('othello'), self.example_user('hamlet'),
'Extremely personal message with a realm emoji :green_tick:!')
realm_emoji_id = realm.get_active_emoji()['green_tick']['id']
realm_emoji_url = "http://zulip.testserver/user_avatars/%s/emoji/images/%s.png" % (
@@ -611,7 +611,7 @@ class TestMissedMessages(ZulipTestCase):
hamlet.emojiset = 'twitter'
hamlet.save(update_fields=['emojiset'])
msg_id = self.send_personal_message(
- self.example_email('othello'), self.example_email('hamlet'),
+ self.example_user('othello'), self.example_user('hamlet'),
'Extremely personal message with a hamburger :hamburger:!')
verify_body_include = ['
']
email_subject = 'PMs with Othello, the Moor of Venice'
@@ -619,7 +619,7 @@ class TestMissedMessages(ZulipTestCase):
def test_stream_link_in_missed_message(self) -> None:
msg_id = self.send_personal_message(
- self.example_email('othello'), self.example_email('hamlet'),
+ self.example_user('othello'), self.example_user('hamlet'),
'Come and join us in #**Verona**.')
stream_id = get_stream('Verona', get_realm('zulip')).id
href = "http://zulip.testserver/#narrow/stream/{stream_id}-Verona".format(stream_id=stream_id)
@@ -629,14 +629,14 @@ class TestMissedMessages(ZulipTestCase):
def test_sender_name_in_missed_message(self) -> None:
hamlet = self.example_user('hamlet')
- msg_id_1 = self.send_stream_message(self.example_email('iago'),
+ msg_id_1 = self.send_stream_message(self.example_user('iago'),
"Denmark",
'@**King Hamlet**')
- msg_id_2 = self.send_stream_message(self.example_email('iago'),
+ msg_id_2 = self.send_stream_message(self.example_user('iago'),
"Verona",
'* 1\n *2')
- msg_id_3 = self.send_personal_message(self.example_email('iago'),
- hamlet.email,
+ msg_id_3 = self.send_personal_message(self.example_user('iago'),
+ hamlet,
'Hello')
handle_missedmessage_emails(hamlet.id, [
@@ -661,11 +661,11 @@ class TestMissedMessages(ZulipTestCase):
def test_multiple_missed_personal_messages(self) -> None:
hamlet = self.example_user('hamlet')
- msg_id_1 = self.send_personal_message(self.example_email('othello'),
- hamlet.email,
+ msg_id_1 = self.send_personal_message(self.example_user('othello'),
+ hamlet,
'Personal Message 1')
- msg_id_2 = self.send_personal_message(self.example_email('iago'),
- hamlet.email,
+ msg_id_2 = self.send_personal_message(self.example_user('iago'),
+ hamlet,
'Personal Message 2')
handle_missedmessage_emails(hamlet.id, [
@@ -680,10 +680,10 @@ class TestMissedMessages(ZulipTestCase):
def test_multiple_stream_messages(self) -> None:
hamlet = self.example_user('hamlet')
- msg_id_1 = self.send_stream_message(self.example_email('othello'),
+ msg_id_1 = self.send_stream_message(self.example_user('othello'),
"Denmark",
'Message1')
- msg_id_2 = self.send_stream_message(self.example_email('iago'),
+ msg_id_2 = self.send_stream_message(self.example_user('iago'),
"Denmark",
'Message2')
@@ -698,10 +698,10 @@ class TestMissedMessages(ZulipTestCase):
def test_multiple_stream_messages_and_mentions(self) -> None:
"""Subject should be stream name and topic as usual."""
hamlet = self.example_user('hamlet')
- msg_id_1 = self.send_stream_message(self.example_email('iago'),
+ msg_id_1 = self.send_stream_message(self.example_user('iago'),
"Denmark",
'Regular message')
- msg_id_2 = self.send_stream_message(self.example_email('othello'),
+ msg_id_2 = self.send_stream_message(self.example_user('othello'),
"Denmark",
'@**King Hamlet**')
@@ -723,17 +723,17 @@ class TestMissedMessages(ZulipTestCase):
self.subscribe(user, stream_name)
late_subscribed_user = self.example_user('hamlet')
- self.send_stream_message(user.email,
+ self.send_stream_message(user,
stream_name,
'Before subscribing')
self.subscribe(late_subscribed_user, stream_name)
- self.send_stream_message(user.email,
+ self.send_stream_message(user,
stream_name,
"After subscribing")
- mention_msg_id = self.send_stream_message(user.email,
+ mention_msg_id = self.send_stream_message(user,
stream_name,
'@**King Hamlet**')
@@ -751,13 +751,13 @@ class TestMissedMessages(ZulipTestCase):
def test_stream_mentions_multiple_people(self) -> None:
"""Subject should be stream name and topic as usual."""
hamlet = self.example_user('hamlet')
- msg_id_1 = self.send_stream_message(self.example_email('iago'),
+ msg_id_1 = self.send_stream_message(self.example_user('iago'),
"Denmark",
'@**King Hamlet**')
- msg_id_2 = self.send_stream_message(self.example_email('othello'),
+ msg_id_2 = self.send_stream_message(self.example_user('othello'),
"Denmark",
'@**King Hamlet**')
- msg_id_3 = self.send_stream_message(self.example_email('cordelia'),
+ msg_id_3 = self.send_stream_message(self.example_user('cordelia'),
"Denmark",
'Regular message')
@@ -773,10 +773,10 @@ class TestMissedMessages(ZulipTestCase):
def test_multiple_stream_messages_different_topics(self) -> None:
"""Should receive separate emails for each topic within a stream."""
hamlet = self.example_user('hamlet')
- msg_id_1 = self.send_stream_message(self.example_email('othello'),
+ msg_id_1 = self.send_stream_message(self.example_user('othello'),
"Denmark",
'Message1')
- msg_id_2 = self.send_stream_message(self.example_email('iago'),
+ msg_id_2 = self.send_stream_message(self.example_user('iago'),
"Denmark",
'Message2',
topic_name="test2")
diff --git a/zerver/tests/test_embedded_bot_system.py b/zerver/tests/test_embedded_bot_system.py
index a144f0415f..0131e2176e 100644
--- a/zerver/tests/test_embedded_bot_system.py
+++ b/zerver/tests/test_embedded_bot_system.py
@@ -23,7 +23,7 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
def test_pm_to_embedded_bot(self) -> None:
assert self.bot_profile is not None
- self.send_personal_message(self.user_profile.email, self.bot_profile.email,
+ self.send_personal_message(self.user_profile, self.bot_profile,
content="help")
last_message = self.get_last_message()
self.assertEqual(last_message.content, "beep boop")
@@ -37,7 +37,7 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
def test_stream_message_to_embedded_bot(self) -> None:
assert self.bot_profile is not None
- self.send_stream_message(self.user_profile.email, "Denmark",
+ self.send_stream_message(self.user_profile, "Denmark",
content="@**{}** foo".format(self.bot_profile.full_name),
topic_name="bar")
last_message = self.get_last_message()
@@ -48,7 +48,7 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
self.assertEqual(display_recipient, "Denmark")
def test_stream_message_not_to_embedded_bot(self) -> None:
- self.send_stream_message(self.user_profile.email, "Denmark",
+ self.send_stream_message(self.user_profile, "Denmark",
content="foo", topic_name="bar")
last_message = self.get_last_message()
self.assertEqual(last_message.content, "foo")
@@ -57,7 +57,7 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
assert self.bot_profile is not None
with patch('zulip_bots.bots.helloworld.helloworld.HelloWorldHandler.initialize',
create=True) as mock_initialize:
- self.send_stream_message(self.user_profile.email, "Denmark",
+ self.send_stream_message(self.user_profile, "Denmark",
content="@**{}** foo".format(self.bot_profile.full_name),
topic_name="bar")
mock_initialize.assert_called_once()
@@ -67,7 +67,7 @@ class TestEmbeddedBotMessaging(ZulipTestCase):
with patch('zulip_bots.bots.helloworld.helloworld.HelloWorldHandler.handle_message',
side_effect=EmbeddedBotQuitException("I'm quitting!")):
with patch('logging.warning') as mock_logging:
- self.send_stream_message(self.user_profile.email, "Denmark",
+ self.send_stream_message(self.user_profile, "Denmark",
content="@**{}** foo".format(self.bot_profile.full_name),
topic_name="bar")
mock_logging.assert_called_once_with("I'm quitting!")
@@ -84,7 +84,7 @@ class TestEmbeddedBotFailures(ZulipTestCase):
service_profile.name = 'invalid'
service_profile.save()
with patch('logging.error') as logging_error_mock:
- self.send_stream_message(user_profile.email, "Denmark",
+ self.send_stream_message(user_profile, "Denmark",
content="@**{}** foo".format(bot_profile.full_name),
topic_name="bar")
logging_error_mock.assert_called_once_with(
diff --git a/zerver/tests/test_event_queue.py b/zerver/tests/test_event_queue.py
index 2927c4a8d0..75e1aa3cf1 100644
--- a/zerver/tests/test_event_queue.py
+++ b/zerver/tests/test_event_queue.py
@@ -200,7 +200,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
client = allocate_client_descriptor(queue_data)
- self.send_stream_message(cordelia.email, stream_name)
+ self.send_stream_message(cordelia, stream_name)
self.assertEqual(len(client.event_queue.contents()), 1)
@@ -253,7 +253,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
client_descriptor = allocate_event_queue()
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
# To test the missed_message hook, we first need to send a message
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark")
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark")
# Verify that nothing happens if you call it as not the
# "last client descriptor", in which case the function
@@ -275,7 +275,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
# Test the hook with a private message; this should trigger notifications
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_personal_message(self.example_email("iago"), email)
+ msg_id = self.send_personal_message(self.example_user("iago"), user_profile)
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
mock_enqueue.assert_called_once()
@@ -289,7 +289,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
# Test the hook with a mention; this should trigger notifications
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="@**King Hamlet** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -304,7 +304,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
# Test the hook with a wildcard mention; this should trigger notifications
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="@**all** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -320,7 +320,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
# themself using a human client; should not notify.
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("hamlet"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("hamlet"), "Denmark",
content="@**all** what's up?",
sending_client_name="website")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
@@ -337,7 +337,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
change_subscription_properties(user_profile, stream, sub, {'is_muted': True})
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="@**all** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -355,7 +355,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
user_profile.save()
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="@**all** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -377,7 +377,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
sub.save()
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="@**all** what's up?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -397,7 +397,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
change_subscription_properties(user_profile, stream, sub, {'push_notifications': True})
client_descriptor = allocate_event_queue()
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="what's up everyone?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -415,7 +415,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
{'push_notifications': False,
'email_notifications': True})
self.assertTrue(client_descriptor.event_queue.empty())
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="what's up everyone?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -436,7 +436,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
self.assertTrue(client_descriptor.event_queue.empty())
do_mute_topic(user_profile, stream, sub.recipient, "mutingtest")
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="what's up everyone?", topic_name="mutingtest")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
@@ -457,7 +457,7 @@ class MissedMessageNotificationsTest(ZulipTestCase):
self.assertTrue(client_descriptor.event_queue.empty())
change_subscription_properties(user_profile, stream, sub, {'is_muted': True})
- msg_id = self.send_stream_message(self.example_email("iago"), "Denmark",
+ msg_id = self.send_stream_message(self.example_user("iago"), "Denmark",
content="what's up everyone?")
with mock.patch("zerver.tornado.event_queue.maybe_enqueue_notifications") as mock_enqueue:
missedmessage_hook(user_profile.id, client_descriptor, True)
diff --git a/zerver/tests/test_events.py b/zerver/tests/test_events.py
index 993eb5398d..b646a3141e 100644
--- a/zerver/tests/test_events.py
+++ b/zerver/tests/test_events.py
@@ -396,8 +396,7 @@ class GetEventsTest(ZulipTestCase):
def test_get_events_narrow(self) -> None:
user_profile = self.example_user('hamlet')
- email = user_profile.email
- self.login(email)
+ self.login(user_profile.email)
def get_message(apply_markdown: bool, client_gravatar: bool) -> Dict[str, Any]:
result = self.tornado_call(
@@ -426,8 +425,8 @@ class GetEventsTest(ZulipTestCase):
self.assert_json_success(result)
self.assert_length(events, 0)
- self.send_personal_message(email, self.example_email("othello"), "hello")
- self.send_stream_message(email, "Denmark", "**hello**")
+ self.send_personal_message(user_profile, self.example_user("othello"), "hello")
+ self.send_stream_message(user_profile, "Denmark", "**hello**")
result = self.tornado_call(get_events, user_profile,
{"queue_id": queue_id,
@@ -621,7 +620,7 @@ class EventsRegisterTest(ZulipTestCase):
for i in range(3):
content = 'mentioning... @**' + user.full_name + '** hello ' + str(i)
self.do_test(
- lambda: self.send_stream_message(self.example_email('cordelia'),
+ lambda: self.send_stream_message(self.example_user('cordelia'),
"Verona",
content)
@@ -631,7 +630,7 @@ class EventsRegisterTest(ZulipTestCase):
for i in range(3):
content = 'mentioning... @**all** hello ' + str(i)
self.do_test(
- lambda: self.send_stream_message(self.example_email('cordelia'),
+ lambda: self.send_stream_message(self.example_user('cordelia'),
"Verona",
content)
@@ -639,19 +638,19 @@ class EventsRegisterTest(ZulipTestCase):
def test_pm_send_message_events(self) -> None:
self.do_test(
- lambda: self.send_personal_message(self.example_email('cordelia'),
- self.example_email('hamlet'),
+ lambda: self.send_personal_message(self.example_user('cordelia'),
+ self.example_user('hamlet'),
'hola')
)
def test_huddle_send_message_events(self) -> None:
huddle = [
- self.example_email('hamlet'),
- self.example_email('othello'),
+ self.example_user('hamlet'),
+ self.example_user('othello'),
]
self.do_test(
- lambda: self.send_huddle_message(self.example_email('cordelia'),
+ lambda: self.send_huddle_message(self.example_user('cordelia'),
huddle,
'hola')
@@ -688,7 +687,7 @@ class EventsRegisterTest(ZulipTestCase):
return schema_checker
events = self.do_test(
- lambda: self.send_stream_message(self.example_email("hamlet"), "Verona", "hello"),
+ lambda: self.send_stream_message(self.example_user("hamlet"), "Verona", "hello"),
client_gravatar=False,
)
schema_checker = get_checker(check_gravatar=check_string)
@@ -696,7 +695,7 @@ class EventsRegisterTest(ZulipTestCase):
self.assert_on_error(error)
events = self.do_test(
- lambda: self.send_stream_message(self.example_email("hamlet"), "Verona", "hello"),
+ lambda: self.send_stream_message(self.example_user("hamlet"), "Verona", "hello"),
client_gravatar=True,
)
schema_checker = get_checker(check_gravatar=equals(None))
@@ -784,8 +783,8 @@ class EventsRegisterTest(ZulipTestCase):
])
message = self.send_personal_message(
- self.example_email("cordelia"),
- self.example_email("hamlet"),
+ self.example_user("cordelia"),
+ self.example_user("hamlet"),
"hello",
)
user_profile = self.example_user('hamlet')
@@ -816,7 +815,7 @@ class EventsRegisterTest(ZulipTestCase):
for content in ['hello', mention]:
message = self.send_stream_message(
- self.example_email('cordelia'),
+ self.example_user('cordelia'),
"Verona",
content
)
@@ -827,13 +826,14 @@ class EventsRegisterTest(ZulipTestCase):
)
def test_send_message_to_existing_recipient(self) -> None:
+ sender = self.example_user('cordelia')
self.send_stream_message(
- self.example_email('cordelia'),
+ sender,
"Verona",
"hello 1"
)
self.do_test(
- lambda: self.send_stream_message("cordelia@zulip.com", "Verona", "hello 2"),
+ lambda: self.send_stream_message(sender, "Verona", "hello 2"),
state_change_expected=True,
)
@@ -852,7 +852,7 @@ class EventsRegisterTest(ZulipTestCase):
])),
])
- message_id = self.send_stream_message(self.example_email("hamlet"), "Verona", "hello")
+ message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
message = Message.objects.get(id=message_id)
events = self.do_test(
lambda: do_add_reaction_legacy(
@@ -877,7 +877,7 @@ class EventsRegisterTest(ZulipTestCase):
])),
])
- message_id = self.send_stream_message(self.example_email("hamlet"), "Verona", "hello")
+ message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
message = Message.objects.get(id=message_id)
do_add_reaction_legacy(self.user_profile, message, "tada")
events = self.do_test(
@@ -903,7 +903,7 @@ class EventsRegisterTest(ZulipTestCase):
])),
])
- message_id = self.send_stream_message(self.example_email("hamlet"), "Verona", "hello")
+ message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
message = Message.objects.get(id=message_id)
events = self.do_test(
lambda: do_add_reaction(
@@ -926,7 +926,7 @@ class EventsRegisterTest(ZulipTestCase):
cordelia = self.example_user('cordelia')
stream_name = 'Verona'
message_id = self.send_stream_message(
- sender_email=cordelia.email,
+ sender=cordelia,
stream_name=stream_name,
)
events = self.do_test(
@@ -957,7 +957,7 @@ class EventsRegisterTest(ZulipTestCase):
])),
])
- message_id = self.send_stream_message(self.example_email("hamlet"), "Verona", "hello")
+ message_id = self.send_stream_message(self.example_user("hamlet"), "Verona", "hello")
message = Message.objects.get(id=message_id)
do_add_reaction(self.user_profile, message, "tada", "1f389", "unicode_emoji")
events = self.do_test(
@@ -2663,7 +2663,8 @@ class EventsRegisterTest(ZulipTestCase):
('stream_id', check_int),
('topic', check_string),
])
- msg_id = self.send_stream_message("hamlet@zulip.com", "Verona")
+ hamlet = self.example_user('hamlet')
+ msg_id = self.send_stream_message(hamlet, "Verona")
message = Message.objects.get(id=msg_id)
events = self.do_test(
lambda: do_delete_messages(self.user_profile.realm, [message]),
@@ -2682,8 +2683,8 @@ class EventsRegisterTest(ZulipTestCase):
('recipient_id', check_int),
])
msg_id = self.send_personal_message(
- self.example_email("cordelia"),
- self.user_profile.email,
+ self.example_user("cordelia"),
+ self.user_profile,
"hello",
)
message = Message.objects.get(id=msg_id)
@@ -2699,7 +2700,7 @@ class EventsRegisterTest(ZulipTestCase):
# Delete all historical messages for this user
user_profile = self.example_user('hamlet')
UserMessage.objects.filter(user_profile=user_profile).delete()
- msg_id = self.send_stream_message("hamlet@zulip.com", "Verona")
+ msg_id = self.send_stream_message(user_profile, "Verona")
message = Message.objects.get(id=msg_id)
self.do_test(
lambda: do_delete_messages(self.user_profile.realm, [message]),
@@ -2773,7 +2774,7 @@ class EventsRegisterTest(ZulipTestCase):
self.subscribe(hamlet, "Denmark")
body = "First message ...[zulip.txt](http://{}".format(hamlet.realm.host) + data['uri'] + ")"
events = self.do_test(
- lambda: self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test"),
+ lambda: self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test"),
num_events=2)
error = schema_checker('events[0]', events[0])
self.assert_on_error(error)
@@ -2945,7 +2946,7 @@ class GetUnreadMsgsTest(ZulipTestCase):
for stream_name, topic_name in tups:
message_ids[topic_name] = [
self.send_stream_message(
- sender_email=cordelia.email,
+ sender=cordelia,
stream_name=stream_name,
topic_name=topic_name,
) for i in range(3)
@@ -2998,16 +2999,16 @@ class GetUnreadMsgsTest(ZulipTestCase):
huddle1_message_ids = [
self.send_huddle_message(
- cordelia.email,
- [hamlet.email, othello.email]
+ cordelia,
+ [hamlet, othello]
)
for i in range(3)
]
huddle2_message_ids = [
self.send_huddle_message(
- cordelia.email,
- [hamlet.email, prospero.email]
+ cordelia,
+ [hamlet, prospero]
)
for i in range(3)
]
@@ -3039,12 +3040,12 @@ class GetUnreadMsgsTest(ZulipTestCase):
hamlet = self.example_user('hamlet')
cordelia_pm_message_ids = [
- self.send_personal_message(cordelia.email, hamlet.email)
+ self.send_personal_message(cordelia, hamlet)
for i in range(3)
]
othello_pm_message_ids = [
- self.send_personal_message(othello.email, hamlet.email)
+ self.send_personal_message(othello, hamlet)
for i in range(3)
]
@@ -3065,9 +3066,9 @@ class GetUnreadMsgsTest(ZulipTestCase):
)
def test_unread_msgs(self) -> None:
- cordelia = self.example_user('cordelia')
- sender_id = cordelia.id
- sender_email = cordelia.email
+ sender = self.example_user('cordelia')
+ sender_id = sender.id
+ sender_email = sender.email
user_profile = self.example_user('hamlet')
othello = self.example_user('othello')
@@ -3075,25 +3076,25 @@ class GetUnreadMsgsTest(ZulipTestCase):
assert(sender_email < user_profile.email)
assert(user_profile.email < othello.email)
- pm1_message_id = self.send_personal_message(sender_email, user_profile.email, "hello1")
- pm2_message_id = self.send_personal_message(sender_email, user_profile.email, "hello2")
+ pm1_message_id = self.send_personal_message(sender, user_profile, "hello1")
+ pm2_message_id = self.send_personal_message(sender, user_profile, "hello2")
muted_stream = self.subscribe(user_profile, 'Muted Stream')
self.mute_stream(user_profile, muted_stream)
self.mute_topic(user_profile, 'Denmark', 'muted-topic')
- stream_message_id = self.send_stream_message(sender_email, "Denmark", "hello")
- muted_stream_message_id = self.send_stream_message(sender_email, "Muted Stream", "hello")
+ stream_message_id = self.send_stream_message(sender, "Denmark", "hello")
+ muted_stream_message_id = self.send_stream_message(sender, "Muted Stream", "hello")
muted_topic_message_id = self.send_stream_message(
- sender_email,
+ sender,
"Denmark",
topic_name="muted-topic",
content="hello",
)
huddle_message_id = self.send_huddle_message(
- sender_email,
- [user_profile.email, othello.email],
+ sender,
+ [user_profile, othello],
'hello3',
)
diff --git a/zerver/tests/test_home.py b/zerver/tests/test_home.py
index a4caacbf4c..cf395baec7 100644
--- a/zerver/tests/test_home.py
+++ b/zerver/tests/test_home.py
@@ -811,7 +811,7 @@ class HomeTest(ZulipTestCase):
def send_test_message(self, content: str, sender_name: str='iago',
stream_name: str='Denmark', topic_name: str='foo') -> None:
- sender = self.example_email(sender_name)
+ sender = self.example_user(sender_name)
self.send_stream_message(sender, stream_name,
content=content, topic_name=topic_name)
diff --git a/zerver/tests/test_import_export.py b/zerver/tests/test_import_export.py
index 23108a790b..8ff50d062f 100644
--- a/zerver/tests/test_import_export.py
+++ b/zerver/tests/test_import_export.py
@@ -98,11 +98,10 @@ from zerver.lib.test_helpers import (
class QueryUtilTest(ZulipTestCase):
def _create_messages(self) -> None:
- for email in [self.example_email('cordelia'),
- self.example_email('hamlet'),
- self.example_email('iago')]:
+ for name in ['cordelia', 'hamlet', 'iago']:
+ user = self.example_user(name)
for _ in range(5):
- self.send_personal_message(email, self.example_email('othello'))
+ self.send_personal_message(user, self.example_user('othello'))
@slow('creates lots of data')
def test_query_chunker(self) -> None:
@@ -458,9 +457,10 @@ class ImportExportTest(ZulipTestCase):
def test_zulip_realm(self) -> None:
realm = Realm.objects.get(string_id='zulip')
- pm_a_msg_id = self.send_personal_message(self.example_email("AARON"), "default-bot@zulip.com")
- pm_b_msg_id = self.send_personal_message("default-bot@zulip.com", self.example_email("iago"))
- pm_c_msg_id = self.send_personal_message(self.example_email("othello"), self.example_email("hamlet"))
+ default_bot = self.example_user('default_bot')
+ pm_a_msg_id = self.send_personal_message(self.example_user("AARON"), default_bot)
+ pm_b_msg_id = self.send_personal_message(default_bot, self.example_user("iago"))
+ pm_c_msg_id = self.send_personal_message(self.example_user("othello"), self.example_user("hamlet"))
realm_emoji = RealmEmoji.objects.get(realm=realm)
realm_emoji.delete()
@@ -502,10 +502,10 @@ class ImportExportTest(ZulipTestCase):
hamlet = self.example_user('hamlet')
user_ids = set([cordelia.id, hamlet.id])
- pm_a_msg_id = self.send_personal_message(self.example_email("AARON"), self.example_email("othello"))
- pm_b_msg_id = self.send_personal_message(self.example_email("cordelia"), self.example_email("iago"))
- pm_c_msg_id = self.send_personal_message(self.example_email("hamlet"), self.example_email("othello"))
- pm_d_msg_id = self.send_personal_message(self.example_email("iago"), self.example_email("hamlet"))
+ pm_a_msg_id = self.send_personal_message(self.example_user("AARON"), self.example_user("othello"))
+ pm_b_msg_id = self.send_personal_message(self.example_user("cordelia"), self.example_user("iago"))
+ pm_c_msg_id = self.send_personal_message(self.example_user("hamlet"), self.example_user("othello"))
+ pm_d_msg_id = self.send_personal_message(self.example_user("iago"), self.example_user("hamlet"))
realm_emoji = RealmEmoji.objects.get(realm=realm)
realm_emoji.delete()
@@ -542,42 +542,42 @@ class ImportExportTest(ZulipTestCase):
create_stream_if_needed(realm, "Private A", invite_only=True)
self.subscribe(self.example_user("iago"), "Private A")
self.subscribe(self.example_user("othello"), "Private A")
- self.send_stream_message(self.example_email("iago"), "Private A", "Hello Stream A")
+ self.send_stream_message(self.example_user("iago"), "Private A", "Hello Stream A")
create_stream_if_needed(realm, "Private B", invite_only=True)
self.subscribe(self.example_user("prospero"), "Private B")
- stream_b_message_id = self.send_stream_message(self.example_email("prospero"),
+ stream_b_message_id = self.send_stream_message(self.example_user("prospero"),
"Private B", "Hello Stream B")
self.subscribe(self.example_user("hamlet"), "Private B")
create_stream_if_needed(realm, "Private C", invite_only=True)
self.subscribe(self.example_user("othello"), "Private C")
self.subscribe(self.example_user("prospero"), "Private C")
- stream_c_message_id = self.send_stream_message(self.example_email("othello"),
+ stream_c_message_id = self.send_stream_message(self.example_user("othello"),
"Private C", "Hello Stream C")
# Create huddles
- self.send_huddle_message(self.example_email("iago"), [self.example_email("cordelia"),
- self.example_email("AARON")])
+ self.send_huddle_message(self.example_user("iago"), [self.example_user("cordelia"),
+ self.example_user("AARON")])
huddle_a = Huddle.objects.last()
- self.send_huddle_message(self.example_email("ZOE"), [self.example_email("hamlet"),
- self.example_email("AARON"),
- self.example_email("othello")])
+ self.send_huddle_message(self.example_user("ZOE"), [self.example_user("hamlet"),
+ self.example_user("AARON"),
+ self.example_user("othello")])
huddle_b = Huddle.objects.last()
huddle_c_message_id = self.send_huddle_message(
- self.example_email("AARON"), [self.example_email("cordelia"),
- self.example_email("ZOE"),
- self.example_email("othello")])
+ self.example_user("AARON"), [self.example_user("cordelia"),
+ self.example_user("ZOE"),
+ self.example_user("othello")])
# Create PMs
- pm_a_msg_id = self.send_personal_message(self.example_email("AARON"), self.example_email("othello"))
- pm_b_msg_id = self.send_personal_message(self.example_email("cordelia"), self.example_email("iago"))
- pm_c_msg_id = self.send_personal_message(self.example_email("hamlet"), self.example_email("othello"))
- pm_d_msg_id = self.send_personal_message(self.example_email("iago"), self.example_email("hamlet"))
+ pm_a_msg_id = self.send_personal_message(self.example_user("AARON"), self.example_user("othello"))
+ pm_b_msg_id = self.send_personal_message(self.example_user("cordelia"), self.example_user("iago"))
+ pm_c_msg_id = self.send_personal_message(self.example_user("hamlet"), self.example_user("othello"))
+ pm_d_msg_id = self.send_personal_message(self.example_user("iago"), self.example_user("hamlet"))
# Send message advertising export and make users react
- self.send_stream_message(self.example_email("othello"), "Verona",
+ self.send_stream_message(self.example_user("othello"), "Verona",
topic_name="Export",
content="Thumbs up for export")
message = Message.objects.last()
@@ -698,24 +698,24 @@ class ImportExportTest(ZulipTestCase):
RealmEmoji.objects.get(realm=original_realm).delete()
# data to test import of huddles
huddle = [
- self.example_email('hamlet'),
- self.example_email('othello')
+ self.example_user('hamlet'),
+ self.example_user('othello')
]
self.send_huddle_message(
- self.example_email('cordelia'), huddle, 'test huddle message'
+ self.example_user('cordelia'), huddle, 'test huddle message'
)
user_mention_message = '@**King Hamlet** Hello'
- self.send_stream_message(self.example_email("iago"), "Verona", user_mention_message)
+ self.send_stream_message(self.example_user("iago"), "Verona", user_mention_message)
stream_mention_message = 'Subscribe to #**Denmark**'
- self.send_stream_message(self.example_email("hamlet"), "Verona", stream_mention_message)
+ self.send_stream_message(self.example_user("hamlet"), "Verona", stream_mention_message)
user_group_mention_message = 'Hello @*hamletcharacters*'
- self.send_stream_message(self.example_email("othello"), "Verona", user_group_mention_message)
+ self.send_stream_message(self.example_user("othello"), "Verona", user_group_mention_message)
special_characters_message = "```\n'\n```\n@**Polonius**"
- self.send_stream_message(self.example_email("iago"), "Denmark", special_characters_message)
+ self.send_stream_message(self.example_user("iago"), "Denmark", special_characters_message)
sample_user = self.example_user('hamlet')
diff --git a/zerver/tests/test_link_embed.py b/zerver/tests/test_link_embed.py
index 2bf7577058..5fa3b7ac46 100644
--- a/zerver/tests/test_link_embed.py
+++ b/zerver/tests/test_link_embed.py
@@ -7,7 +7,7 @@ from requests.exceptions import ConnectionError
from django.test import override_settings
from django.utils.html import escape
-from zerver.models import Message, Realm
+from zerver.models import Message, Realm, UserProfile
from zerver.lib.actions import queue_json_publish
from zerver.lib.test_classes import ZulipTestCase
from zerver.lib.test_helpers import MockPythonResponse
@@ -269,9 +269,9 @@ class PreviewTestCase(ZulipTestCase):
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
def test_edit_message_history(self) -> None:
- email = self.example_email('hamlet')
- self.login(email)
- msg_id = self.send_stream_message(email, "Scotland",
+ user = self.example_user('hamlet')
+ self.login(user.email)
+ msg_id = self.send_stream_message(user, "Scotland",
topic_name="editing", content="original")
url = 'http://test.org/'
@@ -296,13 +296,13 @@ class PreviewTestCase(ZulipTestCase):
self.assertIn(embedded_link, msg.rendered_content)
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
- def _send_message_with_test_org_url(self, sender_email: str, queue_should_run: bool=True,
+ def _send_message_with_test_org_url(self, sender: UserProfile, queue_should_run: bool=True,
relative_url: bool=False) -> Message:
url = 'http://test.org/'
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
msg_id = self.send_personal_message(
- sender_email,
- self.example_email('cordelia'),
+ sender,
+ self.example_user('cordelia'),
content=url,
)
if queue_should_run:
@@ -334,12 +334,12 @@ class PreviewTestCase(ZulipTestCase):
@override_settings(INLINE_URL_EMBED_PREVIEW=True)
def test_message_update_race_condition(self) -> None:
- email = self.example_email('hamlet')
- self.login(email)
+ user = self.example_user('hamlet')
+ self.login(user.email)
original_url = 'http://test.org/'
edited_url = 'http://edited.org/'
with mock.patch('zerver.lib.actions.queue_json_publish') as patched:
- msg_id = self.send_stream_message(email, "Scotland",
+ msg_id = self.send_stream_message(user, "Scotland",
topic_name="foo", content=original_url)
patched.assert_called_once()
queue = patched.call_args[0][0]
@@ -383,30 +383,30 @@ class PreviewTestCase(ZulipTestCase):
embedded_link = 'The Rock'.format(url)
# When humans send, we should get embedded content.
- msg = self._send_message_with_test_org_url(sender_email=self.example_email('hamlet'))
+ msg = self._send_message_with_test_org_url(sender=self.example_user('hamlet'))
self.assertIn(embedded_link, msg.rendered_content)
# We don't want embedded content for bots.
- msg = self._send_message_with_test_org_url(sender_email='webhook-bot@zulip.com',
+ msg = self._send_message_with_test_org_url(sender=self.example_user('webhook_bot'),
queue_should_run=False)
self.assertNotIn(embedded_link, msg.rendered_content)
# Try another human to make sure bot failure was due to the
# bot sending the message and not some other reason.
- msg = self._send_message_with_test_org_url(sender_email=self.example_email('prospero'))
+ msg = self._send_message_with_test_org_url(sender=self.example_user('prospero'))
self.assertIn(embedded_link, msg.rendered_content)
def test_inline_url_embed_preview(self) -> None:
with_preview = '
chalk & cheese
') def test_messages_in_narrow_for_non_search(self) -> None: - email = self.example_email("cordelia") - self.login(email) + user = self.example_user("cordelia") + self.login(user.email) def send(content: str) -> int: msg_id = self.send_stream_message( - sender_email=email, + sender=user, stream_name="Verona", topic_name='test_topic', content=content, @@ -1959,7 +1947,7 @@ class GetOldMessagesTest(ZulipTestCase): returns at most 1 message. """ self.login(self.example_email("cordelia")) - anchor = self.send_stream_message(self.example_email("cordelia"), "Verona") + anchor = self.send_stream_message(self.example_user("cordelia"), "Verona") narrow = [dict(operator='sender', operand=self.example_email("cordelia"))] result = self.get_and_check_messages(dict(narrow=ujson.dumps(narrow), @@ -1985,7 +1973,7 @@ class GetOldMessagesTest(ZulipTestCase): message_ids = [] for i in range(10): - message_ids.append(self.send_stream_message(self.example_email("cordelia"), "Verona")) + message_ids.append(self.send_stream_message(self.example_user("cordelia"), "Verona")) data = self.get_messages_response(anchor=message_ids[9], num_before=9, num_after=0) @@ -2412,8 +2400,8 @@ class GetOldMessagesTest(ZulipTestCase): self.make_stream('England') # Send a few messages that Hamlet won't have UserMessage rows for. - unsub_message_id = self.send_stream_message(cordelia.email, 'England') - self.send_personal_message(cordelia.email, othello.email) + unsub_message_id = self.send_stream_message(cordelia, 'England') + self.send_personal_message(cordelia, othello) self.subscribe(hamlet, 'England') @@ -2423,14 +2411,14 @@ class GetOldMessagesTest(ZulipTestCase): set_topic_mutes(hamlet, muted_topics) # send a muted message - muted_message_id = self.send_stream_message(cordelia.email, 'England', topic_name='muted') + muted_message_id = self.send_stream_message(cordelia, 'England', topic_name='muted') # finally send Hamlet a "normal" message - first_message_id = self.send_stream_message(cordelia.email, 'England') + first_message_id = self.send_stream_message(cordelia, 'England') # send a few more messages - extra_message_id = self.send_stream_message(cordelia.email, 'England') - self.send_personal_message(cordelia.email, hamlet.email) + extra_message_id = self.send_stream_message(cordelia, 'England') + self.send_personal_message(cordelia, hamlet) sa_conn = get_sqlalchemy_connection() @@ -2471,16 +2459,16 @@ class GetOldMessagesTest(ZulipTestCase): # Have Othello send messages to Hamlet that he hasn't read. # Here, Hamlet isn't subscribed to the stream Scotland - self.send_stream_message(self.example_email("othello"), "Scotland") + self.send_stream_message(self.example_user("othello"), "Scotland") first_unread_message_id = self.send_personal_message( - self.example_email("othello"), - self.example_email("hamlet"), + self.example_user("othello"), + self.example_user("hamlet"), ) # Add a few messages that help us test that our query doesn't # look at messages that are irrelevant to Hamlet. - self.send_personal_message(self.example_email("othello"), self.example_email("cordelia")) - self.send_personal_message(self.example_email("othello"), self.example_email("iago")) + self.send_personal_message(self.example_user("othello"), self.example_user("cordelia")) + self.send_personal_message(self.example_user("othello"), self.example_user("iago")) query_params = dict( anchor="first_unread", @@ -2516,18 +2504,18 @@ class GetOldMessagesTest(ZulipTestCase): # Have Othello send messages to Hamlet that he hasn't read. self.subscribe(self.example_user("hamlet"), 'Scotland') - first_unread_message_id = self.send_stream_message(self.example_email("othello"), "Scotland") - self.send_stream_message(self.example_email("othello"), "Scotland") - self.send_stream_message(self.example_email("othello"), "Scotland") + first_unread_message_id = self.send_stream_message(self.example_user("othello"), "Scotland") + self.send_stream_message(self.example_user("othello"), "Scotland") + self.send_stream_message(self.example_user("othello"), "Scotland") self.send_personal_message( - self.example_email("othello"), - self.example_email("hamlet"), + self.example_user("othello"), + self.example_user("hamlet"), ) # Add a few messages that help us test that our query doesn't # look at messages that are irrelevant to Hamlet. - self.send_personal_message(self.example_email("othello"), self.example_email("cordelia")) - self.send_personal_message(self.example_email("othello"), self.example_email("iago")) + self.send_personal_message(self.example_user("othello"), self.example_user("cordelia")) + self.send_personal_message(self.example_user("othello"), self.example_user("iago")) query_params = dict( anchor="first_unread", @@ -2889,7 +2877,7 @@ WHERE user_profile_id = {hamlet_id} AND (content ILIKE '%jumping%' OR subject IL for topic, content in messages_to_search: self.send_stream_message( - sender_email=self.example_email("cordelia"), + sender=self.example_user("cordelia"), stream_name="Verona", content=content, topic_name=topic, diff --git a/zerver/tests/test_outgoing_webhook_interfaces.py b/zerver/tests/test_outgoing_webhook_interfaces.py index a4e4ac96c3..8677903118 100644 --- a/zerver/tests/test_outgoing_webhook_interfaces.py +++ b/zerver/tests/test_outgoing_webhook_interfaces.py @@ -21,7 +21,7 @@ class TestGenericOutgoingWebhookService(ZulipTestCase): # TODO: Ideally, this test would use the full flow, rather # than making a mock message like this. - message_id = self.send_stream_message(self.example_email('othello'), + message_id = self.send_stream_message(self.example_user('othello'), "Denmark", content="@**test**") message = Message.objects.get(id=message_id) wide_message_dict = MessageDict.wide_dict(message) diff --git a/zerver/tests/test_outgoing_webhook_system.py b/zerver/tests/test_outgoing_webhook_system.py index b91e377844..52186738d1 100644 --- a/zerver/tests/test_outgoing_webhook_system.py +++ b/zerver/tests/test_outgoing_webhook_system.py @@ -149,7 +149,7 @@ class TestOutgoingWebhookMessaging(ZulipTestCase): @mock.patch('requests.request', return_value=ResponseMock(200, {"response_string": "Hidley ho, I'm a webhook responding!"})) def test_pm_to_outgoing_webhook_bot(self, mock_requests_request: mock.Mock) -> None: - self.send_personal_message(self.user_profile.email, self.bot_profile.email, + self.send_personal_message(self.user_profile, self.bot_profile, content="foo") last_message = self.get_last_message() self.assertEqual(last_message.content, "Hidley ho, I'm a webhook responding!") @@ -163,7 +163,7 @@ class TestOutgoingWebhookMessaging(ZulipTestCase): @mock.patch('requests.request', return_value=ResponseMock(200, {"response_string": "Hidley ho, I'm a webhook responding!"})) def test_stream_message_to_outgoing_webhook_bot(self, mock_requests_request: mock.Mock) -> None: - self.send_stream_message(self.user_profile.email, "Denmark", + self.send_stream_message(self.user_profile, "Denmark", content="@**{}** foo".format(self.bot_profile.full_name), topic_name="bar") last_message = self.get_last_message() diff --git a/zerver/tests/test_push_notifications.py b/zerver/tests/test_push_notifications.py index c6eacc1c25..94defbac6c 100644 --- a/zerver/tests/test_push_notifications.py +++ b/zerver/tests/test_push_notifications.py @@ -957,7 +957,8 @@ class HandlePushNotificationTest(PushNotificationTest): not long-term idle; we fake it, though, in the sense that the user should not have received the message in the first place""" self.make_stream('public_stream') - message_id = self.send_stream_message("iago@zulip.com", "public_stream", "test") + sender = self.example_user('iago') + message_id = self.send_stream_message(sender, "public_stream", "test") missed_message = {'message_id': message_id} with mock.patch('zerver.lib.push_notifications.logger.error') as mock_logger, \ mock.patch('zerver.lib.push_notifications.push_notifications_enabled', return_value = True) as mock_push_notifications: @@ -977,7 +978,8 @@ class HandlePushNotificationTest(PushNotificationTest): self.subscribe(self.user_profile, 'public_stream') do_soft_deactivate_users([self.user_profile]) - message_id = self.send_stream_message("iago@zulip.com", "public_stream", "test") + sender = self.example_user('iago') + message_id = self.send_stream_message(sender, "public_stream", "test") missed_message = { 'message_id': message_id, 'trigger': 'stream_push_notify', @@ -1136,8 +1138,8 @@ class TestGetAPNsPayload(PushNotificationTest): def test_get_message_payload_apns_personal_message(self) -> None: user_profile = self.example_user("othello") message_id = self.send_personal_message( - self.sender.email, - user_profile.email, + self.sender, + user_profile, 'Content of personal message', ) message = Message.objects.get(id=message_id) @@ -1170,8 +1172,8 @@ class TestGetAPNsPayload(PushNotificationTest): def test_get_message_payload_apns_huddle_message(self, mock_push_notifications: mock.MagicMock) -> None: user_profile = self.example_user("othello") message_id = self.send_huddle_message( - self.sender.email, - [self.example_email('othello'), self.example_email('cordelia')]) + self.sender, + [self.example_user('othello'), self.example_user('cordelia')]) message = Message.objects.get(id=message_id) message.trigger = 'private_message' payload = get_message_payload_apns(user_profile, message) @@ -1306,8 +1308,8 @@ class TestGetAPNsPayload(PushNotificationTest): def test_get_message_payload_apns_redacted_content(self) -> None: user_profile = self.example_user("othello") message_id = self.send_huddle_message( - self.sender.email, - [self.example_email('othello'), self.example_email('cordelia')]) + self.sender, + [self.example_user('othello'), self.example_user('cordelia')]) message = Message.objects.get(id=message_id) message.trigger = 'private_message' payload = get_message_payload_apns(user_profile, message) @@ -1756,7 +1758,7 @@ class TestClearOnRead(ZulipTestCase): hamlet.save() stream = self.subscribe(hamlet, "Denmark") - message_ids = [self.send_stream_message(self.example_email("iago"), + message_ids = [self.send_stream_message(self.example_user("iago"), stream.name, "yo {}".format(i)) for i in range(n_msgs)] diff --git a/zerver/tests/test_queue_worker.py b/zerver/tests/test_queue_worker.py index 2256406e1f..19932a8799 100644 --- a/zerver/tests/test_queue_worker.py +++ b/zerver/tests/test_queue_worker.py @@ -173,26 +173,26 @@ class WorkerTest(ZulipTestCase): othello = self.example_user('othello') hamlet1_msg_id = self.send_personal_message( - from_email=cordelia.email, - to_email=hamlet.email, + from_user=cordelia, + to_user=hamlet, content='hi hamlet', ) hamlet2_msg_id = self.send_personal_message( - from_email=cordelia.email, - to_email=hamlet.email, + from_user=cordelia, + to_user=hamlet, content='goodbye hamlet', ) hamlet3_msg_id = self.send_personal_message( - from_email=cordelia.email, - to_email=hamlet.email, + from_user=cordelia, + to_user=hamlet, content='hello again hamlet', ) othello_msg_id = self.send_personal_message( - from_email=cordelia.email, - to_email=othello.email, + from_user=cordelia, + to_user=othello, content='where art thou, othello?', ) diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py index ed66560a0f..87d5f90675 100644 --- a/zerver/tests/test_reactions.py +++ b/zerver/tests/test_reactions.py @@ -90,7 +90,7 @@ class ReactionEmojiTest(ZulipTestCase): """ stream_name = "Saxony" self.subscribe(self.example_user("cordelia"), stream_name) - message_id = self.send_stream_message(self.example_email("cordelia"), stream_name) + message_id = self.send_stream_message(self.example_user("cordelia"), stream_name) user_profile = self.example_user('hamlet') sender = user_profile.email @@ -650,7 +650,7 @@ class DefaultEmojiReactionTests(EmojiReactionBase): """ stream_name = "Saxony" self.subscribe(self.example_user("cordelia"), stream_name) - message_id = self.send_stream_message(self.example_email("cordelia"), stream_name) + message_id = self.send_stream_message(self.example_user("cordelia"), stream_name) user_profile = self.example_user('hamlet') @@ -814,7 +814,7 @@ class ReactionAPIEventTest(EmojiReactionBase): pm_sender = self.example_user('hamlet') pm_recipient = self.example_user('othello') reaction_sender = pm_recipient - pm_id = self.send_personal_message(pm_sender.email, pm_recipient.email) + pm_id = self.send_personal_message(pm_sender, pm_recipient) expected_recipient_ids = set([pm_sender.id, pm_recipient.id]) reaction_info = { 'emoji_name': 'hamburger', @@ -851,7 +851,7 @@ class ReactionAPIEventTest(EmojiReactionBase): pm_sender = self.example_user('hamlet') pm_recipient = self.example_user('othello') reaction_sender = pm_recipient - pm_id = self.send_personal_message(pm_sender.email, pm_recipient.email) + pm_id = self.send_personal_message(pm_sender, pm_recipient) expected_recipient_ids = set([pm_sender.id, pm_recipient.id]) reaction_info = { 'emoji_name': 'hamburger', diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index ba237619d2..1397205e23 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -848,10 +848,10 @@ class ScrubRealmTest(ZulipTestCase): UserMessage.objects.all().delete() for i in range(5): - self.send_stream_message(iago.email, "Scotland") - self.send_stream_message(othello.email, "Scotland") - self.send_stream_message(cordelia.email, "Shakespeare", sender_realm="lear") - self.send_stream_message(king.email, "Shakespeare", sender_realm="lear") + self.send_stream_message(iago, "Scotland") + self.send_stream_message(othello, "Scotland") + self.send_stream_message(cordelia, "Shakespeare") + self.send_stream_message(king, "Shakespeare") Attachment.objects.filter(realm=zulip).delete() Attachment.objects.create(realm=zulip, owner=iago, path_id="a/b/temp1.txt") diff --git a/zerver/tests/test_retention.py b/zerver/tests/test_retention.py index 644933facb..e9ebb8a987 100644 --- a/zerver/tests/test_retention.py +++ b/zerver/tests/test_retention.py @@ -99,8 +99,7 @@ class ArchiveMessagesTestingBase(RetentionTestingBase): # send messages from mit.edu realm and change messages pub date sender = self.mit_user('espuser') recipient = self.mit_user('starnine') - msg_ids = [self.send_personal_message(sender.email, recipient.email, - sender_realm='zephyr') + msg_ids = [self.send_personal_message(sender, recipient) for i in range(message_quantity)] self._change_messages_date_sent(msg_ids, date_sent) @@ -132,7 +131,6 @@ class ArchiveMessagesTestingBase(RetentionTestingBase): def _send_messages_with_attachments(self) -> Dict[str, int]: user_profile = self.example_user("hamlet") - sender_email = user_profile.email sample_size = 10 host = user_profile.realm.host realm_id = get_realm("zulip").id @@ -150,9 +148,11 @@ class ArchiveMessagesTestingBase(RetentionTestingBase): " http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/temp_file.py.... Some more...." + " http://{host}/user_uploads/{id}/31/4CBjtTLYZhk66pZrF8hnYGwc/abc.py").format(id=realm_id, host=host) - expired_message_id = self.send_stream_message(sender_email, "Denmark", body) - actual_message_id = self.send_stream_message(sender_email, "Denmark", body) - other_message_id = self.send_stream_message("othello@zulip.com", "Denmark", body) + expired_message_id = self.send_stream_message(user_profile, "Denmark", body) + actual_message_id = self.send_stream_message(user_profile, "Denmark", body) + + othello = self.example_user('othello') + other_message_id = self.send_stream_message(othello, "Denmark", body) self._change_messages_date_sent([expired_message_id], timezone_now() - timedelta(days=MIT_REALM_DAYS + 1)) return {'expired_message_id': expired_message_id, 'actual_message_id': actual_message_id, 'other_user_message_id': other_message_id} @@ -227,7 +227,7 @@ class TestArchiveMessagesGeneral(ArchiveMessagesTestingBase): def test_different_stream_realm_policies(self) -> None: verona = get_stream("Verona", self.zulip_realm) - hamlet = self.example_email("hamlet") + hamlet = self.example_user("hamlet") msg_id = self.send_stream_message(hamlet, "Verona", "test") usermsg_ids = self._get_usermessage_ids([msg_id]) @@ -476,8 +476,8 @@ class TestArchivingReactions(ArchiveMessagesTestingBase, EmojiReactionBase): class MoveMessageToArchiveBase(RetentionTestingBase): def setUp(self) -> None: super().setUp() - self.sender = 'hamlet@zulip.com' - self.recipient = 'cordelia@zulip.com' + self.sender = self.example_user('hamlet') + self.recipient = self.example_user('cordelia') def _create_attachments(self) -> None: sample_size = 10 @@ -613,8 +613,8 @@ class MoveMessageToArchiveGeneral(MoveMessageToArchiveBase): msg_id = self.send_personal_message(self.sender, self.recipient, body) # Simulate a reply with the same contents. reply_msg_id = self.send_personal_message( - from_email=self.recipient, - to_email=self.sender, + from_user=self.recipient, + to_user=self.sender, content=body, ) @@ -749,8 +749,8 @@ class TestCleaningArchive(ArchiveMessagesTestingBase): class TestDoDeleteMessages(ZulipTestCase): def test_do_delete_messages_multiple(self) -> None: realm = get_realm("zulip") - cordelia_email = self.example_email('cordelia') - message_ids = [self.send_stream_message(cordelia_email, "Denmark", str(i)) for i in range(0, 10)] + cordelia = self.example_user('cordelia') + message_ids = [self.send_stream_message(cordelia, "Denmark", str(i)) for i in range(0, 10)] messages = Message.objects.filter(id__in=message_ids) with queries_captured() as queries: @@ -771,7 +771,7 @@ class TestDoDeleteMessages(ZulipTestCase): realm = get_realm("zulip") cordelia = self.example_user('cordelia') hamlet = self.example_user('hamlet') - message_id = self.send_personal_message(cordelia.delivery_email, hamlet.delivery_email) + message_id = self.send_personal_message(cordelia, hamlet) message = Message.objects.get(id=message_id) event = { diff --git a/zerver/tests/test_service_bot_system.py b/zerver/tests/test_service_bot_system.py index c02b5ea602..ee0c3d1c35 100644 --- a/zerver/tests/test_service_bot_system.py +++ b/zerver/tests/test_service_bot_system.py @@ -449,15 +449,15 @@ class TestServiceBotEventTriggers(ZulipTestCase): mock_queue_json_publish.side_effect = check_values_passed self.send_stream_message( - self.user_profile.email, + self.user_profile, 'Denmark', content) self.assertTrue(mock_queue_json_publish.called) @mock.patch('zerver.lib.actions.queue_json_publish') def test_no_trigger_on_stream_message_without_mention(self, mock_queue_json_publish: mock.Mock) -> None: - sender_email = self.user_profile.email - self.send_stream_message(sender_email, "Denmark") + sender = self.user_profile + self.send_stream_message(sender, "Denmark") self.assertFalse(mock_queue_json_publish.called) @mock.patch('zerver.lib.actions.queue_json_publish') @@ -467,7 +467,7 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.bot_profile.save() self.send_stream_message( - self.second_bot_profile.email, + self.second_bot_profile, 'Denmark', u'@**FooBot** foo bar!!!') self.assertFalse(mock_queue_json_publish.called) @@ -478,8 +478,8 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.bot_profile.bot_type = bot_type self.bot_profile.save() - sender_email = self.user_profile.email - recipient_email = self.bot_profile.email + sender = self.user_profile + recipient = self.bot_profile def check_values_passed(queue_name: Any, trigger_event: Union[Mapping[Any, Any], Any], @@ -487,16 +487,16 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.assertEqual(queue_name, expected_queue_name) self.assertEqual(trigger_event["user_profile_id"], self.bot_profile.id) self.assertEqual(trigger_event["trigger"], "private_message") - self.assertEqual(trigger_event["message"]["sender_email"], sender_email) + self.assertEqual(trigger_event["message"]["sender_email"], sender.email) display_recipients = [ trigger_event["message"]["display_recipient"][0]["email"], trigger_event["message"]["display_recipient"][1]["email"], ] - self.assertTrue(sender_email in display_recipients) - self.assertTrue(recipient_email in display_recipients) + self.assertTrue(sender.email in display_recipients) + self.assertTrue(recipient.email in display_recipients) mock_queue_json_publish.side_effect = check_values_passed - self.send_personal_message(sender_email, recipient_email, 'test') + self.send_personal_message(sender, recipient, 'test') self.assertTrue(mock_queue_json_publish.called) @mock.patch('zerver.lib.actions.queue_json_publish') @@ -505,9 +505,9 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.bot_profile.bot_type = bot_type self.bot_profile.save() - sender_email = self.second_bot_profile.email - recipient_email = self.bot_profile.email - self.send_personal_message(sender_email, recipient_email) + sender = self.second_bot_profile + recipient = self.bot_profile + self.send_personal_message(sender, recipient) self.assertFalse(mock_queue_json_publish.called) @mock.patch('zerver.lib.actions.queue_json_publish') @@ -519,8 +519,8 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.second_bot_profile.bot_type = bot_type self.second_bot_profile.save() - sender_email = self.user_profile.email - recipient_emails = [self.bot_profile.email, self.second_bot_profile.email] + sender = self.user_profile + recipients = [self.bot_profile, self.second_bot_profile] profile_ids = [self.bot_profile.id, self.second_bot_profile.id] def check_values_passed(queue_name: Any, @@ -530,11 +530,11 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.assertIn(trigger_event["user_profile_id"], profile_ids) profile_ids.remove(trigger_event["user_profile_id"]) self.assertEqual(trigger_event["trigger"], "private_message") - self.assertEqual(trigger_event["message"]["sender_email"], sender_email) + self.assertEqual(trigger_event["message"]["sender_email"], sender.email) self.assertEqual(trigger_event["message"]["type"], u'private') mock_queue_json_publish.side_effect = check_values_passed - self.send_huddle_message(sender_email, recipient_emails, 'test') + self.send_huddle_message(sender, recipients, 'test') self.assertEqual(mock_queue_json_publish.call_count, 2) mock_queue_json_publish.reset_mock() @@ -544,7 +544,7 @@ class TestServiceBotEventTriggers(ZulipTestCase): self.bot_profile.bot_type = bot_type self.bot_profile.save() - sender_email = self.second_bot_profile.email - recipient_emails = [self.user_profile.email, self.bot_profile.email] - self.send_huddle_message(sender_email, recipient_emails) + sender = self.second_bot_profile + recipients = [self.user_profile, self.bot_profile] + self.send_huddle_message(sender, recipients) self.assertFalse(mock_queue_json_publish.called) diff --git a/zerver/tests/test_signup.py b/zerver/tests/test_signup.py index 5b1060eb0f..c8a482e4ee 100644 --- a/zerver/tests/test_signup.py +++ b/zerver/tests/test_signup.py @@ -156,9 +156,9 @@ class AddNewUserHistoryTest(ZulipTestCase): stream = Stream.objects.get(realm=realm, name='Denmark') DefaultStream.objects.create(stream=stream, realm=realm) # Make sure at least 3 messages are sent to Denmark and it's a default stream. - message_id = self.send_stream_message(self.example_email('hamlet'), stream.name, "test 1") - self.send_stream_message(self.example_email('hamlet'), stream.name, "test 2") - self.send_stream_message(self.example_email('hamlet'), stream.name, "test 3") + message_id = self.send_stream_message(self.example_user('hamlet'), stream.name, "test 1") + self.send_stream_message(self.example_user('hamlet'), stream.name, "test 2") + self.send_stream_message(self.example_user('hamlet'), stream.name, "test 3") with patch("zerver.lib.actions.add_new_user_history"): self.register(self.nonreg_email('test'), "test") @@ -169,7 +169,7 @@ class AddNewUserHistoryTest(ZulipTestCase): # Sent a message afterwards to trigger a race between message # sending and `add_new_user_history`. - race_message_id = self.send_stream_message(self.example_email('hamlet'), + race_message_id = self.send_stream_message(self.example_user('hamlet'), streams[0].name, "test") # Overwrite ONBOARDING_UNREAD_MESSAGES to 2 @@ -1043,13 +1043,13 @@ class InviteUserTest(InviteUserBase): self.make_stream(private_stream_name, invite_only=True) self.subscribe(user_profile, private_stream_name) public_msg_id = self.send_stream_message( - self.example_email("hamlet"), + self.example_user("hamlet"), "Denmark", topic_name="Public topic", content="Public message", ) secret_msg_id = self.send_stream_message( - self.example_email("hamlet"), + self.example_user("hamlet"), private_stream_name, topic_name="Secret topic", content="Secret message", diff --git a/zerver/tests/test_soft_deactivation.py b/zerver/tests/test_soft_deactivation.py index 6b05bab665..3f2c7fac36 100644 --- a/zerver/tests/test_soft_deactivation.py +++ b/zerver/tests/test_soft_deactivation.py @@ -41,8 +41,7 @@ class UserSoftDeactivationTests(ZulipTestCase): # We are sending this message to ensure that users have at least # one UserMessage row. - self.send_huddle_message(users[0].email, - [user.email for user in users]) + self.send_huddle_message(users[0], users) with mock.patch('logging.info'): do_soft_deactivate_users(users) @@ -87,8 +86,8 @@ class UserSoftDeactivationTests(ZulipTestCase): self.example_user('iago'), self.example_user('cordelia'), ] - self.send_huddle_message(users[0].email, - [user.email for user in users]) + self.send_huddle_message(users[0], users) + with mock.patch('logging.info'): do_soft_deactivate_users(users) for user in users: @@ -139,7 +138,7 @@ class UserSoftDeactivationTests(ZulipTestCase): for user in users: self.assertTrue(user.long_term_idle) - message_id = self.send_stream_message(hamlet.email, stream, 'Hello world!') + message_id = self.send_stream_message(hamlet, stream, 'Hello world!') already_received = UserMessage.objects.filter(message_id=message_id).count() with mock.patch('logging.info'): do_catch_up_soft_deactivated_users(users) @@ -188,7 +187,7 @@ class UserSoftDeactivationTests(ZulipTestCase): # Verify that deactivated users are caught up automatically - message_id = self.send_stream_message(sender.email, stream_name) + message_id = self.send_stream_message(sender, stream_name) received_count = UserMessage.objects.filter(user_profile__in=users, message_id=message_id).count() self.assertEqual(0, received_count) @@ -204,7 +203,7 @@ class UserSoftDeactivationTests(ZulipTestCase): # Verify that deactivated users are NOT caught up if # AUTO_CATCH_UP_SOFT_DEACTIVATED_USERS is off - message_id = self.send_stream_message(sender.email, stream_name) + message_id = self.send_stream_message(sender, stream_name) received_count = UserMessage.objects.filter(user_profile__in=users, message_id=message_id).count() self.assertEqual(0, received_count) diff --git a/zerver/tests/test_submessage.py b/zerver/tests/test_submessage.py index b199b4cdf7..a85b7a8d88 100644 --- a/zerver/tests/test_submessage.py +++ b/zerver/tests/test_submessage.py @@ -20,7 +20,7 @@ class TestBasics(ZulipTestCase): stream_name = 'Verona' message_id = self.send_stream_message( - sender_email=cordelia.email, + sender=cordelia, stream_name=stream_name, ) @@ -80,7 +80,7 @@ class TestBasics(ZulipTestCase): cordelia = self.example_user('cordelia') stream_name = 'Verona' message_id = self.send_stream_message( - sender_email=cordelia.email, + sender=cordelia, stream_name=stream_name, ) self.login(cordelia.email) @@ -95,8 +95,8 @@ class TestBasics(ZulipTestCase): hamlet = self.example_user('hamlet') bad_message_id = self.send_personal_message( - from_email=hamlet.email, - to_email=hamlet.email, + from_user=hamlet, + to_user=hamlet, ) payload = dict( message_id=bad_message_id, @@ -111,7 +111,7 @@ class TestBasics(ZulipTestCase): hamlet = self.example_user('hamlet') stream_name = 'Verona' message_id = self.send_stream_message( - sender_email=cordelia.email, + sender=cordelia, stream_name=stream_name, ) self.login(cordelia.email) diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 5bfeb25f42..3e129dad2e 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -3122,9 +3122,9 @@ class SubscriptionAPITest(ZulipTestCase): self.subscribe(random_user, "stream2") self.subscribe(random_user, "private_stream") - self.send_stream_message(random_user.email, "stream1", "test", "test") - self.send_stream_message(random_user.email, "stream2", "test", "test") - self.send_stream_message(random_user.email, "private_stream", "test", "test") + self.send_stream_message(random_user, "stream1", "test", "test") + self.send_stream_message(random_user, "stream2", "test", "test") + self.send_stream_message(random_user, "private_stream", "test", "test") def get_unread_stream_data() -> List[Dict[str, Any]]: raw_unread_data = get_raw_unread_data(user) @@ -3445,15 +3445,16 @@ class InviteOnlyStreamTest(ZulipTestCase): If you try to send a message to an invite-only stream to which you aren't subscribed, you'll get a 400. """ - self.login(self.example_email("hamlet")) + user = self.example_user('hamlet') + self.login(user.email) # Create Saxony as an invite-only stream. self.assert_json_success( - self.common_subscribe_to_streams(self.example_email("hamlet"), ["Saxony"], + self.common_subscribe_to_streams(user.email, ["Saxony"], invite_only=True)) - email = self.example_email("cordelia") + cordelia = self.example_user("cordelia") with self.assertRaises(JsonableError): - self.send_stream_message(email, "Saxony") + self.send_stream_message(cordelia, "Saxony") def test_list_respects_invite_only_bit(self) -> None: """ diff --git a/zerver/tests/test_tutorial.py b/zerver/tests/test_tutorial.py index 347aa768ef..1741a17a26 100644 --- a/zerver/tests/test_tutorial.py +++ b/zerver/tests/test_tutorial.py @@ -4,7 +4,7 @@ from django.conf import settings from zerver.lib.actions import internal_send_private_message from zerver.lib.test_classes import ZulipTestCase from zerver.lib.test_helpers import message_stream_count, most_recent_message -from zerver.models import get_realm, get_user, get_system_bot, UserProfile +from zerver.models import get_system_bot, UserProfile import ujson @@ -35,33 +35,30 @@ class TutorialTests(ZulipTestCase): self.assertEqual(user.tutorial_status, expected_db_status) def test_single_response_to_pm(self) -> None: - realm = get_realm('zulip') user_email = 'hamlet@zulip.com' - bot_email = 'welcome-bot@zulip.com' + user = self.example_user('hamlet') + bot = get_system_bot(settings.WELCOME_BOT) content = 'whatever' self.login(user_email) - self.send_personal_message(user_email, bot_email, content) - user = get_user(user_email, realm) + self.send_personal_message(user, bot, content) user_messages = message_stream_count(user) expected_response = ("Congratulations on your first reply! :tada:\n\n" "Feel free to continue using this space to practice your new messaging " "skills. Or, try clicking on some of the stream names to your left!") self.assertEqual(most_recent_message(user).content, expected_response) # Welcome bot shouldn't respond to further PMs. - self.send_personal_message(user_email, bot_email, content) + self.send_personal_message(user, bot, content) self.assertEqual(message_stream_count(user), user_messages+1) def test_no_response_to_group_pm(self) -> None: - realm = get_realm('zulip') # Assume realm is always 'zulip' - user1_email = self.example_email('hamlet') - user2_email = self.example_email('cordelia') - bot_email = self.example_email('welcome_bot') + user1 = self.example_user('hamlet') + user2 = self.example_user('cordelia') + bot = get_system_bot(settings.WELCOME_BOT) content = "whatever" - self.login(user1_email) - self.send_huddle_message(user1_email, [bot_email, user2_email], content) - user1 = get_user(user1_email, realm) + self.login(user1.email) + self.send_huddle_message(user1, [bot, user2], content) user1_messages = message_stream_count(user1) self.assertEqual(most_recent_message(user1).content, content) # Welcome bot should still respond to initial PM after group PM. - self.send_personal_message(user1_email, bot_email, content) + self.send_personal_message(user1, bot, content) self.assertEqual(message_stream_count(user1), user1_messages+2) diff --git a/zerver/tests/test_unread.py b/zerver/tests/test_unread.py index 97eaae23cb..18fa35fc45 100644 --- a/zerver/tests/test_unread.py +++ b/zerver/tests/test_unread.py @@ -39,7 +39,7 @@ class PointerTest(ZulipTestCase): """ self.login(self.example_email("hamlet")) self.assertEqual(self.example_user('hamlet').pointer, -1) - msg_id = self.send_stream_message(self.example_email("othello"), "Verona") + msg_id = self.send_stream_message(self.example_user("othello"), "Verona") result = self.client_post("/json/users/me/pointer", {"pointer": msg_id}) self.assert_json_success(result) self.assertEqual(self.example_user('hamlet').pointer, msg_id) @@ -51,7 +51,7 @@ class PointerTest(ZulipTestCase): user = self.example_user('hamlet') email = user.email self.assertEqual(user.pointer, -1) - msg_id = self.send_stream_message(self.example_email("othello"), "Verona") + msg_id = self.send_stream_message(self.example_user("othello"), "Verona") result = self.api_post(email, "/api/v1/users/me/pointer", {"pointer": msg_id}) self.assert_json_success(result) self.assertEqual(get_user(email, user.realm).pointer, msg_id) @@ -104,7 +104,7 @@ class PointerTest(ZulipTestCase): self.assert_json_success(result) # Send a new message (this will be unread) - new_message_id = self.send_stream_message(self.example_email("othello"), "Verona", + new_message_id = self.send_stream_message(self.example_user("othello"), "Verona", "test") # If we call get_messages with use_first_unread_anchor=True, we @@ -183,7 +183,7 @@ class PointerTest(ZulipTestCase): result = self.client_post("/json/mark_all_as_read") self.assert_json_success(result) - new_message_id = self.send_stream_message(self.example_email("othello"), "Verona", + new_message_id = self.send_stream_message(self.example_user("othello"), "Verona", "test") messages_response = self.get_messages_response( @@ -215,16 +215,16 @@ class UnreadCountTests(ZulipTestCase): return_value = True) as mock_push_notifications_enabled: self.unread_msg_ids = [ self.send_personal_message( - self.example_email("iago"), self.example_email("hamlet"), "hello"), + self.example_user("iago"), self.example_user("hamlet"), "hello"), self.send_personal_message( - self.example_email("iago"), self.example_email("hamlet"), "hello2")] + self.example_user("iago"), self.example_user("hamlet"), "hello2")] mock_push_notifications_enabled.assert_called() # Sending a new message results in unread UserMessages being created def test_new_message(self) -> None: self.login(self.example_email("hamlet")) content = "Test message for unset read bit" - last_msg = self.send_stream_message(self.example_email("hamlet"), "Verona", content) + last_msg = self.send_stream_message(self.example_user("hamlet"), "Verona", content) user_messages = list(UserMessage.objects.filter(message=last_msg)) self.assertEqual(len(user_messages) > 0, True) for um in user_messages: @@ -267,8 +267,8 @@ class UnreadCountTests(ZulipTestCase): stream = self.subscribe(user_profile, "test_stream") self.subscribe(self.example_user("cordelia"), "test_stream") - message_id = self.send_stream_message(self.example_email("hamlet"), "test_stream", "hello") - unrelated_message_id = self.send_stream_message(self.example_email("hamlet"), "Denmark", "hello") + message_id = self.send_stream_message(self.example_user("hamlet"), "test_stream", "hello") + unrelated_message_id = self.send_stream_message(self.example_user("hamlet"), "Denmark", "hello") events = [] # type: List[Mapping[str, Any]] with tornado_redirected_to_list(events): @@ -323,8 +323,8 @@ class UnreadCountTests(ZulipTestCase): user_profile = self.example_user('hamlet') self.subscribe(user_profile, "test_stream") - message_id = self.send_stream_message(self.example_email("hamlet"), "test_stream", "hello", "test_topic") - unrelated_message_id = self.send_stream_message(self.example_email("hamlet"), "Denmark", "hello", "Denmark2") + message_id = self.send_stream_message(self.example_user("hamlet"), "test_stream", "hello", "test_topic") + unrelated_message_id = self.send_stream_message(self.example_user("hamlet"), "Denmark", "hello", "Denmark2") events = [] # type: List[Mapping[str, Any]] with tornado_redirected_to_list(events): result = self.client_post("/json/mark_topic_as_read", { @@ -371,7 +371,7 @@ class FixUnreadTests(ZulipTestCase): def send_message(stream_name: str, topic_name: str) -> int: msg_id = self.send_stream_message( - self.example_email("othello"), + self.example_user("othello"), stream_name, topic_name=topic_name) um = UserMessage.objects.get( @@ -507,9 +507,9 @@ class PushNotificationMarkReadFlowsTest(ZulipTestCase): self.assert_json_success(result) self.assertEqual(self.get_mobile_push_notification_ids(user_profile), []) - message_id = self.send_stream_message(self.example_email("cordelia"), "test_stream", "hello", "test_topic") - second_message_id = self.send_stream_message(self.example_email("cordelia"), "test_stream", "hello", "other_topic") - third_message_id = self.send_stream_message(self.example_email("cordelia"), "second_stream", "hello", "test_topic") + message_id = self.send_stream_message(self.example_user("cordelia"), "test_stream", "hello", "test_topic") + second_message_id = self.send_stream_message(self.example_user("cordelia"), "test_stream", "hello", "other_topic") + third_message_id = self.send_stream_message(self.example_user("cordelia"), "second_stream", "hello", "test_topic") self.assertEqual(self.get_mobile_push_notification_ids(user_profile), [message_id, second_message_id, third_message_id]) @@ -530,7 +530,7 @@ class PushNotificationMarkReadFlowsTest(ZulipTestCase): self.assertEqual(self.get_mobile_push_notification_ids(user_profile), [third_message_id]) - fourth_message_id = self.send_stream_message(self.example_email("cordelia"), "test_stream", "hello", "test_topic") + fourth_message_id = self.send_stream_message(self.example_user("cordelia"), "test_stream", "hello", "test_topic") self.assertEqual(self.get_mobile_push_notification_ids(user_profile), [third_message_id, fourth_message_id]) diff --git a/zerver/tests/test_upload.py b/zerver/tests/test_upload.py index eb7e9c851d..fabda45623 100644 --- a/zerver/tests/test_upload.py +++ b/zerver/tests/test_upload.py @@ -199,7 +199,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): self.subscribe(self.example_user("hamlet"), "Denmark") body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")" - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content) def test_file_download_unauthed(self) -> None: @@ -264,7 +264,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): # Send message referring only dummy_1 self.subscribe(self.example_user("hamlet"), "Denmark") body = "Some files here ...[zulip.txt](http://localhost:9991/user_uploads/" + d1_path_id + ")" - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") # dummy_2 should not exist in database or the uploads folder do_delete_old_unclaimed_attachments(2) @@ -276,7 +276,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): self.login(hamlet.email) body = "Test message ...[zulip.txt](http://localhost:9991/user_uploads/%s/64/fake_path_id.txt)" % ( hamlet.realm_id,) - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") self.assertFalse(Attachment.objects.filter(path_id = "1/64/fake_path_id.txt").exists()) def test_multiple_claim_attachments(self) -> None: @@ -293,9 +293,9 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): self.subscribe(self.example_user("hamlet"), "Denmark") host = self.example_user('hamlet').realm.host body = "First message ...[zulip.txt](http://{}/user_uploads/".format(host) + d1_path_id + ")" - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") body = "Second message ...[zulip.txt](http://{}/user_uploads/".format(host) + d1_path_id + ")" - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 2) @@ -314,25 +314,25 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): # First, send the message to the new private stream. body = "First message ...[zulip.txt](http://{}/user_uploads/".format(host) + d1_path_id + ")" - self.send_stream_message(self.example_email("hamlet"), "private_stream", body, "test") + self.send_stream_message(self.example_user("hamlet"), "private_stream", body, "test") self.assertFalse(Attachment.objects.get(path_id=d1_path_id).is_realm_public) self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 1) # Then, try having a user who didn't receive the message try to publish it, and fail body = "Illegal message ...[zulip.txt](http://{}/user_uploads/".format(host) + d1_path_id + ")" - self.send_stream_message(self.example_email("cordelia"), "Denmark", body, "test") + self.send_stream_message(self.example_user("cordelia"), "Denmark", body, "test") self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 1) self.assertFalse(Attachment.objects.get(path_id=d1_path_id).is_realm_public) # Then, have the owner PM it to another user, giving that other user access. body = "Second message ...[zulip.txt](http://{}/user_uploads/".format(host) + d1_path_id + ")" - self.send_personal_message(self.example_email("hamlet"), self.example_email("othello"), body) + self.send_personal_message(self.example_user("hamlet"), self.example_user("othello"), body) self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 2) self.assertFalse(Attachment.objects.get(path_id=d1_path_id).is_realm_public) # Then, have that new recipient user publish it. body = "Third message ...[zulip.txt](http://{}/user_uploads/".format(host) + d1_path_id + ")" - self.send_stream_message(self.example_email("othello"), "Denmark", body, "test") + self.send_stream_message(self.example_user("othello"), "Denmark", body, "test") self.assertEqual(Attachment.objects.get(path_id=d1_path_id).messages.count(), 3) self.assertTrue(Attachment.objects.get(path_id=d1_path_id).is_realm_public) @@ -356,7 +356,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): self.subscribe(hamlet, "test") body = ("[f1.txt](http://{}/user_uploads/".format(host) + f1_path_id + ") " "[f2.txt](http://{}/user_uploads/".format(host) + f2_path_id + ")") - msg_id = self.send_stream_message(hamlet.email, "test", body, "test") + msg_id = self.send_stream_message(hamlet, "test", body, "test") result = self.client_post("/json/user_uploads", {'file': f3}) f3_path_id = re.sub('/user_uploads/', '', result.json()['uri']) @@ -511,7 +511,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): uri = result.json()['uri'] fp_path_id = re.sub('/user_uploads/', '', uri) body = "First message ...[zulip.txt](http://{}/user_uploads/".format(user.realm.host) + fp_path_id + ")" - self.send_stream_message(user.email, stream_name, body, "test") + self.send_stream_message(user, stream_name, body, "test") self.logout() # Owner user should be able to view file @@ -564,7 +564,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): uri = result.json()['uri'] fp_path_id = re.sub('/user_uploads/', '', uri) body = "First message ...[zulip.txt](http://{}/user_uploads/".format(user.realm.host) + fp_path_id + ")" - self.send_stream_message(user.email, stream_name, body, "test") + self.send_stream_message(user, stream_name, body, "test") self.logout() # Add aaron as a subscribed after the message was sent @@ -632,7 +632,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): fp_path_id = re.sub('/user_uploads/', '', uri) for i in range(20): body = "First message ...[zulip.txt](http://{}/user_uploads/".format(hamlet.realm.host) + fp_path_id + ")" - self.send_stream_message(self.example_email("hamlet"), "test-subscribe %s" % (i % 5,), body, "test") + self.send_stream_message(self.example_user("hamlet"), "test-subscribe %s" % (i % 5,), body, "test") self.logout() user = self.example_user("aaron") @@ -674,7 +674,7 @@ class FileUploadTest(UploadSerializeMixin, ZulipTestCase): uri = result.json()['uri'] fp_path_id = re.sub('/user_uploads/', '', uri) body = "First message ...[zulip.txt](http://{}/user_uploads/".format(realm.host) + fp_path_id + ")" - self.send_stream_message(self.example_email("hamlet"), "test-subscribe", body, "test") + self.send_stream_message(self.example_user("hamlet"), "test-subscribe", body, "test") self.logout() # Now all users should be able to access the files @@ -1513,7 +1513,7 @@ class S3Test(ZulipTestCase): self.subscribe(self.example_user("hamlet"), "Denmark") body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")" - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") self.assertIn('title="dummy.txt"', self.get_last_message().rendered_content) @use_s3_backend @@ -1567,7 +1567,7 @@ class S3Test(ZulipTestCase): self.subscribe(self.example_user("hamlet"), "Denmark") body = "First message ...[zulip.txt](http://localhost:9991" + uri + ")" - self.send_stream_message(self.example_email("hamlet"), "Denmark", body, "test") + self.send_stream_message(self.example_user("hamlet"), "Denmark", body, "test") self.assertIn('title="zulip.txt"', self.get_last_message().rendered_content) @use_s3_backend diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index 3eeb18547b..73cec4b983 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -1283,7 +1283,7 @@ class GetProfileTest(ZulipTestCase): def common_get_profile(self, user_id: str) -> Dict[str, Any]: # Assumes all users are example users in realm 'zulip' user_profile = self.example_user(user_id) - self.send_stream_message(user_profile.email, "Verona", "hello") + self.send_stream_message(user_profile, "Verona", "hello") result = self.api_get(user_profile.email, "/api/v1/users/me") @@ -1365,8 +1365,8 @@ class GetProfileTest(ZulipTestCase): Ensure GET /users/me returns a proper pointer id after the pointer is updated """ - id1 = self.send_stream_message(self.example_email("othello"), "Verona") - id2 = self.send_stream_message(self.example_email("othello"), "Verona") + id1 = self.send_stream_message(self.example_user("othello"), "Verona") + id2 = self.send_stream_message(self.example_user("othello"), "Verona") json = self.common_get_profile("hamlet")