Index: tests/test_page_outputs.py |
diff --git a/tests/test_page_outputs.py b/tests/test_page_outputs.py |
index f117b5836d40c3b9cff1b255121a0f3d0add3085..125bd69e941a330bce98376ca8c8db06792a229b 100644 |
--- a/tests/test_page_outputs.py |
+++ b/tests/test_page_outputs.py |
@@ -1,6 +1,7 @@ |
import os |
import sys |
import runpy |
+from threading import Thread |
import mock |
import pytest |
@@ -9,6 +10,16 @@ import urllib2 |
from .conftest import ROOTPATH |
from .utils import get_dir_contents, run_test_server |
from cms.sources import FileSource |
+import cms.bin.test_server as test_server |
+ |
+ |
+class ParametersTestServer: |
+ def __init__(self): |
+ pass |
+ source = None |
+ host = 'localhost' |
+ port = 5001 |
+ base_url = 'http://{0}:{1}/'.format(host, port) |
def get_expected_outputs(test_type): |
@@ -40,12 +51,35 @@ def static_output(request, temp_site): |
return static_out_path |
-@pytest.fixture(scope='module') |
+@pytest.fixture(scope='session') |
def dynamic_server(temp_site): |
with run_test_server(temp_site) as ts: |
yield ts |
+@pytest.fixture(scope='function') |
+def dynamic_server_failing_import(temp_site, monkeypatch): |
Vasily Kuznetsov
2018/10/16 13:18:23
This fixture should probably just be called `dynam
Tudor Avram
2018/10/18 13:44:05
Done.
|
+ |
+ mock_params = ParametersTestServer() |
+ mock_params.source = FileSource(str(temp_site)) |
+ |
+ test_server.Parameters = mock_params |
+ |
+ run_fn = test_server.make_builtins_server() |
+ |
+ thread = Thread(target=run_fn, args=(mock_params.host, mock_params.port, |
+ test_server.handler), |
+ kwargs={'use_reloader': True, 'use_debugger': True}) |
+ thread.daemon = True |
+ thread.start() |
+ |
+ yield mock_params.base_url |
+ |
+ monkeypatch.setattr(test_server, 'get_data', lambda x: sys.exit()) |
+ with pytest.raises(urllib2.HTTPError): |
+ urllib2.urlopen(mock_params.base_url + 'some_page') |
Vasily Kuznetsov
2018/10/16 13:18:23
I think it would be better to join the thread here
Tudor Avram
2018/10/18 13:44:05
No longer relevant
|
+ |
+ |
@pytest.fixture(scope='session') |
def output_pages(static_output): |
return get_dir_contents(static_output) |
@@ -68,3 +102,11 @@ def test_dynamic(dynamic_server, filename, expected_output): |
def test_cache(output_pages): |
source = FileSource(os.path.join('test_site')) |
assert source.get_cache_dir() == os.path.join('test_site', 'cache') |
+ |
+ |
+def test_dynamic_builtins(dynamic_server_failing_import): |
+ page, expected_output = dynamic_expected_outputs[0] |
+ |
+ response = urllib2.urlopen(dynamic_server_failing_import + page) |
+ |
+ assert expected_output in response.read().strip() |