emails: Redirect to /emails after generating emails.

This commit is contained in:
Vishnu Ks 2017-09-29 18:38:45 +00:00 committed by Tim Abbott
parent 8964e04238
commit 4c2e787ffc
3 changed files with 15 additions and 19 deletions

View File

@ -2,7 +2,9 @@
{% block content %} {% block content %}
<div class="container"> <div class="container">
<div class="alert"> <div class="alert">
{{ message |safe }} All the emails sent in the Zulip development environment are logged here. You can also
manually generate most of the emails by clicking <a href="/emails/generate">here</a>.
To clear this log click <a href="/emails/clear">here</a>
</div> </div>
{{ log |safe }} {{ log |safe }}
</div> </div>

View File

@ -77,13 +77,17 @@ class DocPageTest(ZulipTestCase):
self._test('/errors/5xx/', 'Internal server error') self._test('/errors/5xx/', 'Internal server error')
# For reaching full coverage for clear_emails function # For reaching full coverage for clear_emails function
os.remove(settings.EMAIL_CONTENT_LOG_PATH) self._test('/emails/', 'manually generate most of the emails by clicking')
if os.path.isfile(settings.EMAIL_CONTENT_LOG_PATH):
os.remove(settings.EMAIL_CONTENT_LOG_PATH)
result = self.client_get('/emails/clear/') result = self.client_get('/emails/clear/')
self.assertEqual(result.status_code, 302) self.assertEqual(result.status_code, 302)
self.assertIn('emails', result['Location']) result = self.client_get(result['Location'])
self.assertIn('manually generate most of the emails by clicking', str(result.content))
self._test('/emails/', 'manually generate most of the emails by clicking') result = self.client_get('/emails/generate/')
self._test('/emails/generate/', 'Emails generated successfully') self.assertEqual(result.status_code, 302)
self.assertIn('emails', result['Location'])
self._test('/register/', 'Sign up for Zulip') self._test('/register/', 'Sign up for Zulip')
result = self.client_get('/integrations/doc-html/nonexistent_integration', follow=True) result = self.client_get('/integrations/doc-html/nonexistent_integration', follow=True)

View File

@ -17,20 +17,14 @@ import datetime
ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../') ZULIP_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../')
client = Client() client = Client()
def email_page(request, message=None): def email_page(request):
# type: (HttpRequest, Optional[str]) -> HttpResponse # type: (HttpRequest) -> HttpResponse
if message is None:
message = '''
All the emails sent in the Zulip development environment are logged here. You can also
manually generate most of the emails by clicking <a href="/emails/generate">here</a>.
To clear this log click <a href="/emails/clear">here</a>.
'''
try: try:
with open(settings.EMAIL_CONTENT_LOG_PATH, "r+") as f: with open(settings.EMAIL_CONTENT_LOG_PATH, "r+") as f:
content = f.read() content = f.read()
except FileNotFoundError: except FileNotFoundError:
content = "" content = ""
return render(request, 'zerver/email_log.html', {'log': content, 'message': message}) return render(request, 'zerver/email_log.html', {'log': content})
def clear_emails(request): def clear_emails(request):
# type: (HttpRequest) -> HttpResponse # type: (HttpRequest) -> HttpResponse
@ -79,8 +73,4 @@ def generate_all_emails(request):
# Follow up day1 day2 emails # Follow up day1 day2 emails
enqueue_welcome_emails(user_profile) enqueue_welcome_emails(user_profile)
message = ''' return redirect(email_page)
Emails generated successfully. Reload this page to generate them again.
To clear this log click <a href="/emails/clear">here</a>.
'''
return email_page(request, message)