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

Unified Diff: tests/test_page_outputs.py

Issue 29912588: Issue 7019 - [CMS] Refactor `test_server.py` (Closed)
Patch Set: Addressed commments from Patch Set #1. Objectified server handler. Added test cases. Created Oct. 18, 2018, 1:41 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/utils.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_page_outputs.py
diff --git a/tests/test_page_outputs.py b/tests/test_page_outputs.py
index f117b5836d40c3b9cff1b255121a0f3d0add3085..b47510cfc54907639873f7a9e2fc6a37170a9809 100644
--- a/tests/test_page_outputs.py
+++ b/tests/test_page_outputs.py
@@ -9,6 +9,7 @@ import urllib2
from .conftest import ROOTPATH
from .utils import get_dir_contents, run_test_server
from cms.sources import FileSource
+from cms.bin.test_server import DynamicServerHandler
def get_expected_outputs(test_type):
@@ -40,9 +41,23 @@ def static_output(request, temp_site):
return static_out_path
-@pytest.fixture(scope='module')
-def dynamic_server(temp_site):
- with run_test_server(temp_site) as ts:
+@pytest.fixture(scope='function')
+def dynamic_server_werkzeug(temp_site):
+ with run_test_server(str(temp_site)) as ts:
+ yield ts
+
+
+@pytest.fixture(scope='function')
+def dynamic_server_builtins(temp_site, tmpdir):
+ werkzeug_dir = tmpdir.mkdir('werkzeug')
+ werkzeug_dir.join('__init__.py').write('raise ImportError')
+ werkzeug_dir.join('serving.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
@@ -59,12 +74,69 @@ def test_static(output_pages, filename, expected_output):
assert expected_output == output_pages[filename]
-@pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
-def test_dynamic(dynamic_server, filename, expected_output):
- response = urllib2.urlopen(dynamic_server + filename)
- assert expected_output == response.read().strip()
-
-
def test_cache(output_pages):
source = FileSource(os.path.join('test_site'))
assert source.get_cache_dir() == os.path.join('test_site', 'cache')
+
+
+@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'
+
+ with pytest.raises(urllib2.HTTPError) as err:
+ urllib2.urlopen(dynamic_server_werkzeug + filename)
+
+ assert exp_msg in str(err.value)
+
+
+@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'
+
+ with pytest.raises(urllib2.HTTPError) as err:
+ urllib2.urlopen(dynamic_server_builtins + filename)
+
+ assert exp_msg in str(err.value)
+
+
+@pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
+def test_dynamic_server_handler(filename, expected_output, temp_site):
+ def cleanup(page):
+ return page.replace(os.linesep, '').strip()
+
+ handler = DynamicServerHandler('localhost', 5000, str(temp_site))
+ environ = {'PATH_INFO': filename}
+
+ generated_page = handler(environ, lambda x, y: None)
+
+ assert cleanup(expected_output) == cleanup(generated_page[0])
+
+
+@pytest.mark.parametrize('page', ['en/translate', '/en/translate'])
+def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts):
+ handler = DynamicServerHandler('localhost', 5000,
+ str(temp_site_with_conflicts))
+ environ = {'PATH_INFO': page}
+
+ with pytest.raises(Exception) as err:
+ handler(environ, lambda x, y: None)
+
+ assert str(err.value) == 'The requested page conflicts with another page.'
« no previous file with comments | « tests/conftest.py ('k') | tests/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld