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

Unified 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.
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
Index: sitescripts/reports/tests/test_updateReport.py
===================================================================
new file mode 100644
--- /dev/null
+++ b/sitescripts/reports/tests/test_updateReport.py
@@ -0,0 +1,76 @@
+# This file is part of the Adblock Plus web scripts,
+# Copyright (C) 2017-present eyeo GmbH
+#
+# Adblock Plus is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# Adblock Plus is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
+
+from urllib import urlencode
+from urllib2 import urlopen, HTTPError
+
+import pytest
+from wsgi_intercept import (urllib_intercept, add_wsgi_intercept,
+ remove_wsgi_intercept)
+
+from sitescripts.reports.web.updateReport import handleRequest
+
+HOST = 'localhost'
+PORT = 3306
+
+PLAINTEXT_GUID = '12345678-1234-1234-1234-123456789abc'
+
+
+@pytest.fixture
+def response_for():
+ """ Registers two intercepts, returns responses for them based on bool """
+ urllib_intercept.install_opener()
+ add_wsgi_intercept(HOST, PORT, lambda: handleRequest,
+ script_name='test script_name')
+
+ def response_for(data):
+ url = 'http://{}:{}'.format(HOST, PORT)
+ if data is None:
+ response = urlopen(url)
+ else:
+ response = urlopen(url, urlencode(data))
+ return response.code, response.read()
+
+ yield response_for
+ remove_wsgi_intercept()
+
+
+@pytest.fixture
+def form_data():
+ return {
+ 'email': 'john_doe@gmail.com',
+ 'secret': '92b3e705f2abe74c20c1c5ea9abd9ba2',
+ 'guid': PLAINTEXT_GUID,
+ 'status': 'test STATUS',
+ 'usefulness': 'test USEFULNESS',
+ 'notify': 'test NOTIFY'
+ }
+
+
+@pytest.mark.parametrize('field,message', [
+ (('guid', ''), 'Invalid or missing report GUID'),
+ (('secret', ''), 'Wrong secret value'),
+])
+def test_http_errs(field, message, response_for, form_data):
+ key, value = field
+ form_data[key] = value
+ with pytest.raises(HTTPError) as error:
+ response_for(form_data)
+
+ assert message in error.value.read()
+
+
+def test_success(response_for, form_data):
+ assert response_for(form_data) == 'test RESULT'

Powered by Google App Engine
This is Rietveld