-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
controllers/default: 303 redirect after sponsor_renew_request #841
To avoid potential resent emails on refresh, send a 303 redirect to the current page after successful e-mail send. This means we need to store the flash message in the session, which isn't ideal, but is already on our radar anyway.
- Loading branch information
Showing
2 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,54 @@ def test_sponsor_renew(self): | |
self.assertEqual(str(out['all_row_categories'][2]['title']), 'Expired sponsorships') | ||
self.assertEqual([r.OTT_ID for r in out['all_row_categories'][2]['rows']], [r.OTT_ID for r in rs]) | ||
|
||
def test_sponsor_renew_request(self): | ||
email_1, user_1 = '[email protected]', '1_bettyunittestexamplecom' | ||
|
||
def srr(user_identifier): | ||
current.request.scheme = True | ||
current.request.extension = 'html' | ||
current.request.controller = 'default' | ||
current.request.function = 'sponsor_renew_request' | ||
current.request.vars.clear() | ||
current.session.flash = None | ||
current.globalenv['myconf']['smtp'] = dict(autosend_email=0) | ||
if user_identifier: | ||
current.request.vars['user_identifier'] = user_identifier | ||
current.request.vars['_formname'] = 'default' | ||
try: | ||
out = default.sponsor_renew_request() | ||
except HTTP as e: | ||
return dict( | ||
status=e.status, | ||
location=e.headers.get('Location'), | ||
flash=current.session.flash, | ||
) | ||
return dict( | ||
status=current.response.status, | ||
flash=current.session.flash, | ||
form_errors=dict(out['form'].errors), | ||
form_latest=dict(out['form'].latest), | ||
) | ||
|
||
# Empty form, no message | ||
self.assertEqual(srr(None), dict( | ||
status=200, | ||
flash=None, | ||
form_errors={}, | ||
form_latest={'user_identifier': None}, | ||
)) | ||
# Sumbit something, get told we'll send an e-mail in a redirect (not a 200) | ||
self.assertEqual(srr(user_1), dict( | ||
status=303, | ||
location='/sponsor_renew_request', | ||
flash='If the user %s exists in our database, we will send them an email' % user_1, | ||
)) | ||
self.assertEqual(srr(email_1), dict( | ||
status=303, | ||
location='/sponsor_renew_request', | ||
flash='If the user %s exists in our database, we will send them an email' % email_1, | ||
)) | ||
|
||
|
||
if __name__ == '__main__': | ||
import sys | ||
|