Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/formmail/test/test_formmail2.py

Issue 29386649: Issue #5011 - Moves formmail template load to handler creation (Closed) Base URL: https://hg.adblockplus.org/sitescripts
Patch Set: Created March 17, 2017, 3:46 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | sitescripts/formmail/web/formmail2.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/formmail/test/test_formmail2.py
===================================================================
--- a/sitescripts/formmail/test/test_formmail2.py
+++ b/sitescripts/formmail/test/test_formmail2.py
@@ -57,16 +57,56 @@
else:
response = urlopen(url, urlencode(data))
return response.code, response.read()
yield response_for
remove_wsgi_intercept()
+def test_form_handler_email_errors(form_config):
+ tmp_config = form_config
+ del tmp_config['url'].value
+ with pytest.raises(Exception) as error:
+ formmail2.make_handler('test', tmp_config)[1]
+ assert error.value.message == 'No URL configured for form handler: test'
+
+
+def test_form_handler_field_errors(form_config):
+ tmp_config = form_config
+ tmp_config['fields'] = {}
+ with pytest.raises(Exception) as error:
+ formmail2.make_handler('test', tmp_config)[1]
+ assert error.value.message == 'No fields configured for form handler: test'
+
+ del tmp_config['fields']
+ with pytest.raises(Exception) as error:
+ formmail2.make_handler('test', tmp_config)[1]
+ assert error.value.message == 'No fields configured for form handler: test'
+
+
+def test_form_handler_template_errors(form_config):
+ tmp_config = form_config
+ tmp_config['template'].value = 'no'
+ with pytest.raises(Exception) as error:
+ formmail2.make_handler('test', tmp_config)[1]
+ assert error.typename == 'TemplateNotFound'
+
+ del tmp_config['template'].value
+ with pytest.raises(Exception) as error:
+ formmail2.make_handler('test', tmp_config)[1]
+ assert error.value.message == ('No template configured for form handler'
+ ': test')
+ del tmp_config['template']
+ with pytest.raises(Exception) as error:
+ formmail2.make_handler('test', tmp_config)[1]
+ assert error.value.message == ('No template configured for form handler'
+ ': test')
+
+
def test_config_parse(form_config):
assert form_config['url'].value == 'test/apply/submit'
assert form_config['fields']['email'].value == 'mandatory, email'
def test_success(response_for, form_data, mocker):
sm_mock = mocker.patch('sitescripts.formmail.web.formmail2.sendMail')
assert response_for(form_data) == (200, '')
« no previous file with comments | « no previous file | sitescripts/formmail/web/formmail2.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld