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

Side by Side Diff: sitescripts/reports/tests/test_updateReport.py

Issue 29993614: Issue 2267 - Unify form handling by reusing form_handler() (Closed) Base URL: https://hg.adblockplus.org/sitescripts/
Patch Set: Created Jan. 30, 2019, 11:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2017-present eyeo GmbH
3 #
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
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 from urllib import urlencode
17 from urllib2 import urlopen, HTTPError
18
19 import pytest
20 from wsgi_intercept import (urllib_intercept, add_wsgi_intercept,
21 remove_wsgi_intercept)
22
23 from sitescripts.reports.web.updateReport import handleRequest
24
25 HOST = 'localhost'
26 PORT = 3306
27
28 PLAINTEXT_GUID = '12345678-1234-1234-1234-123456789abc'
29
30
31 @pytest.fixture
32 def response_for():
33 """ Registers two intercepts, returns responses for them based on bool """
34 urllib_intercept.install_opener()
35 add_wsgi_intercept(HOST, PORT, lambda: handleRequest,
36 script_name='test script_name')
37
38 def response_for(data):
39 url = 'http://{}:{}'.format(HOST, PORT)
40 if data is None:
41 response = urlopen(url)
42 else:
43 response = urlopen(url, urlencode(data))
44 return response.code, response.read()
45
46 yield response_for
47 remove_wsgi_intercept()
48
49
50 @pytest.fixture
51 def form_data():
52 return {
53 'email': 'john_doe@gmail.com',
54 'secret': '92b3e705f2abe74c20c1c5ea9abd9ba2',
55 'guid': PLAINTEXT_GUID,
56 'status': 'test STATUS',
57 'usefulness': 'test USEFULNESS',
58 'notify': 'test NOTIFY'
59 }
60
61
62 @pytest.mark.parametrize('field,message', [
63 (('guid', ''), 'Invalid or missing report GUID'),
64 (('secret', ''), 'Wrong secret value'),
65 ])
66 def test_http_errs(field, message, response_for, form_data):
67 key, value = field
68 form_data[key] = value
69 with pytest.raises(HTTPError) as error:
70 response_for(form_data)
71
72 assert message in error.value.read()
73
74
75 def test_success(response_for, form_data):
76 assert response_for(form_data) == 'test RESULT'
OLDNEW

Powered by Google App Engine
This is Rietveld