mirror of
https://github.com/zulip/zulip.git
synced 2025-11-03 13:33:24 +00:00
Fixes #2665. Regenerated by tabbott with `lint --fix` after a rebase and change in parameters. Note from tabbott: In a few cases, this converts technical debt in the form of unsorted imports into different technical debt in the form of our largest files having very long, ugly import sequences at the start. I expect this change will increase pressure for us to split those files, which isn't a bad thing. Signed-off-by: Anders Kaseorg <anders@zulip.com>
44 lines
2.0 KiB
Python
44 lines
2.0 KiB
Python
import os
|
|
from unittest import mock
|
|
|
|
from django.conf import settings
|
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
from zproject.email_backends import get_forward_address
|
|
|
|
|
|
class EmailLogTest(ZulipTestCase):
|
|
def test_generate_and_clear_email_log(self) -> None:
|
|
with self.settings(EMAIL_BACKEND='zproject.email_backends.EmailLogBackEnd'), \
|
|
mock.patch('zproject.email_backends.EmailLogBackEnd.send_email_smtp'), \
|
|
mock.patch('logging.info', return_value=None), \
|
|
self.settings(DEVELOPMENT_LOG_EMAILS=True):
|
|
result = self.client_get('/emails/generate/')
|
|
self.assertEqual(result.status_code, 302)
|
|
self.assertIn('emails', result['Location'])
|
|
|
|
result = self.client_get("/emails/")
|
|
self.assert_in_success_response(["All the emails sent in the Zulip"], result)
|
|
|
|
result = self.client_get('/emails/clear/')
|
|
self.assertEqual(result.status_code, 302)
|
|
result = self.client_get(result['Location'])
|
|
self.assertIn('manually generate most of the emails by clicking', str(result.content))
|
|
|
|
def test_forward_address_details(self) -> None:
|
|
forward_address = "forward-to@example.com"
|
|
result = self.client_post("/emails/", {"forward_address": forward_address})
|
|
self.assert_json_success(result)
|
|
|
|
self.assertEqual(get_forward_address(), forward_address)
|
|
|
|
with self.settings(EMAIL_BACKEND='zproject.email_backends.EmailLogBackEnd'), \
|
|
mock.patch('logging.info', return_value=None):
|
|
with mock.patch('zproject.email_backends.EmailLogBackEnd.send_email_smtp'):
|
|
result = self.client_get('/emails/generate/')
|
|
self.assertEqual(result.status_code, 302)
|
|
self.assertIn('emails', result['Location'])
|
|
result = self.client_get(result['Location'])
|
|
self.assert_in_success_response([forward_address], result)
|
|
os.remove(settings.FORWARD_ADDRESS_CONFIG_FILE)
|