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

Unified Diff: tests/test_dynamic_server.py

Issue 29912588: Issue 7019 - [CMS] Refactor `test_server.py` (Closed)
Patch Set: Added timeout option when setting up server Created Oct. 24, 2018, 3:57 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 | « tests/conftest.py ('k') | tests/test_page_outputs.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_dynamic_server.py
diff --git a/tests/test_dynamic_server.py b/tests/test_dynamic_server.py
new file mode 100644
index 0000000000000000000000000000000000000000..7f8fa00491b5283c7482c136339a2eac55325ae8
--- /dev/null
+++ b/tests/test_dynamic_server.py
@@ -0,0 +1,63 @@
+import pytest
+import urllib2
+import os
+
+from tests.test_page_outputs import dynamic_expected_outputs
+from tests.utils import run_test_server, exception_test
+
+
+@pytest.fixture(scope='function')
+def dynamic_server_werkzeug(temp_site):
+ """Test server run using the `werkzeug` module."""
+ with run_test_server(str(temp_site)) as ts:
+ yield ts
+
+
+@pytest.fixture(scope='function')
+def dynamic_server_builtins(temp_site, tmpdir):
+ """Test server run using builtin modules."""
+ # Creating an invalid `werkzeug` module and add it to the head of the
+ # PYTHONPATH. This would cause the import of `werkzeug` to fail when
+ # running the test server and force it to use the builtin modules.
+ werkzeug_dir = tmpdir.mkdir('werkzeug')
+ werkzeug_dir.join('__init__.py').write('raise ImportError')
+ new_env = dict(os.environ)
+ new_env['PYTHONPATH'] = os.pathsep.join([str(tmpdir),
+ os.getenv('PYTHONPATH', '')])
+
+ with run_test_server(str(temp_site), new_env) as ts:
+ yield ts
+
+
+@pytest.mark.slowtest
+def test_dynamic_werkzeug_good_page(dynamic_server_werkzeug):
+ filename, expected_output = dynamic_expected_outputs[0]
+ response = urllib2.urlopen(dynamic_server_werkzeug + filename)
+
+ assert expected_output in response.read().strip()
+
+
+@pytest.mark.slowtest
+def test_dynamic_werkzeug_not_found(dynamic_server_werkzeug):
+ filename = 'en/no-page-here'
+ exp_msg = 'Not Found'
+
+ exception_test(urllib2.urlopen, urllib2.HTTPError, exp_msg,
+ dynamic_server_werkzeug + filename)
+
+
+@pytest.mark.slowtest
+def test_dynamic_builtins_good_page(dynamic_server_builtins):
+ filename, expected_output = dynamic_expected_outputs[0]
+ response = urllib2.urlopen(dynamic_server_builtins + filename)
+
+ assert expected_output in response.read().strip()
+
+
+@pytest.mark.slowtest
+def test_dynamic_builtins_not_found(dynamic_server_builtins):
+ filename = 'en/no-page-here'
+ exp_msg = 'Not Found'
+
+ exception_test(urllib2.urlopen, urllib2.HTTPError, exp_msg,
+ dynamic_server_builtins + filename)
« no previous file with comments | « tests/conftest.py ('k') | tests/test_page_outputs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld