mirror of https://github.com/zulip/zulip.git
emails: Don't log emails while running test suite.
Modified the tests to ensure 100% coverage.
This commit is contained in:
parent
d8c19cb003
commit
6aa4b64dc0
|
@ -6,24 +6,23 @@ from zerver.lib.test_classes import ZulipTestCase
|
||||||
from zproject.email_backends import get_forward_address
|
from zproject.email_backends import get_forward_address
|
||||||
|
|
||||||
class EmailLogTest(ZulipTestCase):
|
class EmailLogTest(ZulipTestCase):
|
||||||
def test_get_email_log_page(self) -> None:
|
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/")
|
result = self.client_get("/emails/")
|
||||||
self.assert_in_success_response(["All the emails sent in the Zulip"], result)
|
self.assert_in_success_response(["All the emails sent in the Zulip"], result)
|
||||||
|
|
||||||
def test_clear_email_logs(self) -> None:
|
|
||||||
result = self.client_get('/emails/clear/')
|
result = self.client_get('/emails/clear/')
|
||||||
self.assertEqual(result.status_code, 302)
|
self.assertEqual(result.status_code, 302)
|
||||||
result = self.client_get(result['Location'])
|
result = self.client_get(result['Location'])
|
||||||
self.assertIn('manually generate most of the emails by clicking', str(result.content))
|
self.assertIn('manually generate most of the emails by clicking', str(result.content))
|
||||||
|
|
||||||
def test_generate_emails(self) -> None:
|
|
||||||
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'])
|
|
||||||
|
|
||||||
def test_forward_address_details(self) -> None:
|
def test_forward_address_details(self) -> None:
|
||||||
forward_address = "forward-to@example.com"
|
forward_address = "forward-to@example.com"
|
||||||
result = self.client_post("/emails/", {"forward_address": forward_address})
|
result = self.client_post("/emails/", {"forward_address": forward_address})
|
||||||
|
|
|
@ -89,9 +89,10 @@ class EmailLogBackEnd(BaseEmailBackend):
|
||||||
|
|
||||||
def send_messages(self, email_messages: List[EmailMultiAlternatives]) -> int:
|
def send_messages(self, email_messages: List[EmailMultiAlternatives]) -> int:
|
||||||
for email in email_messages:
|
for email in email_messages:
|
||||||
self.log_email(email)
|
|
||||||
if get_forward_address():
|
if get_forward_address():
|
||||||
self.send_email_smtp(email)
|
self.send_email_smtp(email)
|
||||||
|
if settings.DEVELOPMENT_LOG_EMAILS:
|
||||||
|
self.log_email(email)
|
||||||
email_log_url = settings.ROOT_DOMAIN_URI + "/emails"
|
email_log_url = settings.ROOT_DOMAIN_URI + "/emails"
|
||||||
logging.info("Emails sent in development are available at %s" % (email_log_url,))
|
logging.info("Emails sent in development are available at %s" % (email_log_url,))
|
||||||
return len(email_messages)
|
return len(email_messages)
|
||||||
|
|
|
@ -240,6 +240,10 @@ DEFAULT_SETTINGS = {
|
||||||
# We use SubMessage for now-experimental features like
|
# We use SubMessage for now-experimental features like
|
||||||
# slash commands.
|
# slash commands.
|
||||||
'ALLOW_SUB_MESSAGES': DEVELOPMENT,
|
'ALLOW_SUB_MESSAGES': DEVELOPMENT,
|
||||||
|
|
||||||
|
# We log emails in development environment for accessing
|
||||||
|
# them easily through /emails page
|
||||||
|
'DEVELOPMENT_LOG_EMAILS': DEVELOPMENT,
|
||||||
}
|
}
|
||||||
|
|
||||||
# These settings are not documented in prod_settings_template.py.
|
# These settings are not documented in prod_settings_template.py.
|
||||||
|
|
|
@ -158,3 +158,7 @@ PUSH_NOTIFICATION_BOUNCER_URL = None
|
||||||
SLOW_QUERY_LOGS_STREAM = None
|
SLOW_QUERY_LOGS_STREAM = None
|
||||||
|
|
||||||
THUMBOR_URL = 'http://127.0.0.1:9995'
|
THUMBOR_URL = 'http://127.0.0.1:9995'
|
||||||
|
|
||||||
|
# Logging the emails while running the tests adds them
|
||||||
|
# to /emails page.
|
||||||
|
DEVELOPMENT_LOG_EMAILS = False
|
||||||
|
|
Loading…
Reference in New Issue