From 224acb8256131c3b3d1e2a29fd001fb1ebce2e2d Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 27 Apr 2018 13:53:18 -0700 Subject: [PATCH] email_mirror: Add a test for sending to a private stream. This verifies an important case. We still have an open bug for why in some production environments, the email_gateway_bot seems to not be tagged as an API super user (resulting in this code path not working). --- zerver/tests/test_email_mirror.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/zerver/tests/test_email_mirror.py b/zerver/tests/test_email_mirror.py index e6c729a586..e31d1b40ec 100644 --- a/zerver/tests/test_email_mirror.py +++ b/zerver/tests/test_email_mirror.py @@ -125,6 +125,31 @@ class TestStreamEmailMessagesSuccess(ZulipTestCase): self.assertEqual(get_display_recipient(message.recipient), stream.name) self.assertEqual(message.topic_name(), "(no topic)") + def test_receive_private_stream_email_messages_success(self) -> None: + user_profile = self.example_user('hamlet') + self.login(user_profile.email) + self.make_stream("private_stream", invite_only=True) + self.subscribe(user_profile, "private_stream") + stream = get_stream("private_stream", user_profile.realm) + + stream_to_address = encode_email_address(stream) + + incoming_valid_message = MIMEText('TestStreamEmailMessages Body') # type: Any # https://github.com/python/typeshed/issues/275 + + incoming_valid_message['Subject'] = 'TestStreamEmailMessages Subject' + incoming_valid_message['From'] = self.example_email('hamlet') + incoming_valid_message['To'] = stream_to_address + incoming_valid_message['Reply-to'] = self.example_email('othello') + + process_message(incoming_valid_message) + + # Hamlet is subscribed to this stream so should see the email message from Othello. + message = most_recent_message(user_profile) + + self.assertEqual(message.content, "TestStreamEmailMessages Body") + self.assertEqual(get_display_recipient(message.recipient), stream.name) + self.assertEqual(message.topic_name(), incoming_valid_message['Subject']) + class TestStreamEmailMessagesEmptyBody(ZulipTestCase): def test_receive_stream_email_messages_empty_body(self) -> None: