Index: tests/test_page_outputs.py |
diff --git a/tests/test_page_outputs.py b/tests/test_page_outputs.py |
index f117b5836d40c3b9cff1b255121a0f3d0add3085..295b94da8916ed93d8b49d5e3f10aede9b70f832 100644 |
--- a/tests/test_page_outputs.py |
+++ b/tests/test_page_outputs.py |
@@ -7,8 +7,9 @@ import pytest |
import urllib2 |
from .conftest import ROOTPATH |
-from .utils import get_dir_contents, run_test_server |
+from .utils import get_dir_contents, run_test_server, exception_test |
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') |
Vasily Kuznetsov
2018/10/22 14:36:48
Perhaps we can add a comment here explaining what
Tudor Avram
2018/10/23 16:44:35
Done.
|
+ werkzeug_dir.join('__init__.py').write('raise ImportError') |
+ werkzeug_dir.join('serving.py').write('raise ImportError') |
Vasily Kuznetsov
2018/10/22 14:36:47
It seems that this line is actually not necessary.
Tudor Avram
2018/10/23 16:44:35
Done.
|
+ |
+ 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,63 @@ 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 |
Vasily Kuznetsov
2018/10/22 14:36:48
It seems that now these four slowtests with relate
Tudor Avram
2018/10/23 16:44:34
Done.
|
+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) |
+ |
+ |
+@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} |
+ exp_msg = 'The requested page conflicts with another page.' |
+ |
+ exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) |