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

Side by Side Diff: sitescripts/formmail/test/test_formmail.py

Issue 29984589: 7123 - Fixes Pytest DeprecationWarning (Closed) Base URL: https://hg.adblockplus.org/sitescripts/
Patch Set: Created Jan. 17, 2019, 8:46 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 94
95 @pytest.mark.parametrize('key,message', [ 95 @pytest.mark.parametrize('key,message', [
96 ('url', 'No URL configured for form handler: test'), 96 ('url', 'No URL configured for form handler: test'),
97 ('fields', 'No fields configured for form handler: test'), 97 ('fields', 'No fields configured for form handler: test'),
98 ('template', 'No template configured for form handler: test'), 98 ('template', 'No template configured for form handler: test'),
99 ]) 99 ])
100 def test_config_errors(key, message, form_config): 100 def test_config_errors(key, message, form_config):
101 del form_config[key] 101 del form_config[key]
102 with pytest.raises(Exception) as error: 102 with pytest.raises(Exception) as error:
103 formmail.make_handler('test', form_config)[1] 103 formmail.make_handler('test', form_config)[1]
104 assert error.value.message == message 104 assert str(error.value) == message
105 105
106 106
107 @pytest.mark.parametrize('field,message', [ 107 @pytest.mark.parametrize('field,message', [
108 (('new_field', 'foo'), 'Unexpected field/fields: new_field'), 108 (('new_field', 'foo'), 'Unexpected field/fields: new_field'),
109 (('mandatory', ''), 'No mandatory entered'), 109 (('mandatory', ''), 'No mandatory entered'),
110 (('non_mandatory_email', 'asfaf'), 'Invalid email'), 110 (('non_mandatory_email', 'asfaf'), 'Invalid email'),
111 (('email', 'asfaf'), 'You failed the email validation'), 111 (('email', 'asfaf'), 'You failed the email validation'),
112 (('email', ''), 'You failed the email test'), 112 (('email', ''), 'You failed the email test'),
113 ]) 113 ])
114 def test_http_errs(field, message, response_for, form_data, sm_mock): 114 def test_http_errs(field, message, response_for, form_data, sm_mock):
(...skipping 30 matching lines...) Expand all
145 row = reader.next() 145 row = reader.next()
146 # rows should not be equal because the time field 146 # rows should not be equal because the time field
147 # is added by the logging function. 147 # is added by the logging function.
148 assert row != reader.next() 148 assert row != reader.next()
149 149
150 150
151 def test_config_field_errors(form_config): 151 def test_config_field_errors(form_config):
152 form_config['fields'] = {} 152 form_config['fields'] = {}
153 with pytest.raises(Exception) as error: 153 with pytest.raises(Exception) as error:
154 formmail.make_handler('test', form_config)[1] 154 formmail.make_handler('test', form_config)[1]
155 assert error.value.message == 'No fields configured for form handler: test' 155 assert str(error.value) == 'No fields configured for form handler: test'
156 156
157 157
158 def test_config_template_errors(form_config): 158 def test_config_template_errors(form_config):
159 form_config['template'].value = 'no' 159 form_config['template'].value = 'no'
160 with pytest.raises(Exception) as error: 160 with pytest.raises(Exception) as error:
161 formmail.make_handler('test', form_config)[1] 161 formmail.make_handler('test', form_config)[1]
162 assert error.value.message == 'Template not found at: no' 162 assert str(error.value) == 'Template not found at: no'
163 163
164 164
165 def test_config_parse(form_config): 165 def test_config_parse(form_config):
166 assert form_config['url'].value == 'test/apply/submit' 166 assert form_config['url'].value == 'test/apply/submit'
167 assert form_config['fields']['email'].value == 'mandatory, email' 167 assert form_config['fields']['email'].value == 'mandatory, email'
168 168
169 169
170 def test_sendmail_fail(log_path, response_for, form_data, sm_mock): 170 def test_sendmail_fail(log_path, response_for, form_data, sm_mock):
171 sm_mock.side_effect = Exception('Sendmail Fail') 171 sm_mock.side_effect = Exception('Sendmail Fail')
172 with pytest.raises(HTTPError): 172 with pytest.raises(HTTPError):
(...skipping 17 matching lines...) Expand all
190 # this should append the second form to the error log file 190 # this should append the second form to the error log file
191 with pytest.raises(Exception): 191 with pytest.raises(Exception):
192 formmail.log_formdata(form_data, log_path) 192 formmail.log_formdata(form_data, log_path)
193 with pytest.raises(Exception): 193 with pytest.raises(Exception):
194 formmail.log_formdata(form_data, log_path) 194 formmail.log_formdata(form_data, log_path)
195 195
196 with open(log_path + '_error') as error_log: 196 with open(log_path + '_error') as error_log:
197 reader = DictReader(error_log) 197 reader = DictReader(error_log)
198 assert reader.next() == form_data 198 assert reader.next() == form_data
199 assert reader.next() == form_data 199 assert reader.next() == form_data
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld