Index: tests/test_page_outputs.py |
=================================================================== |
--- a/tests/test_page_outputs.py |
+++ b/tests/test_page_outputs.py |
@@ -9,25 +9,34 @@ |
from conftest import ROOTPATH |
def get_dir_contents(path): |
return_data = {} |
for dirpath, dirnames, filenames in os.walk(path): |
for output_file in filenames: |
with open(os.path.join(dirpath, output_file)) as f: |
- return_data[output_file] = f.read() |
+ return_data[output_file] = f.read().strip() |
Vasily Kuznetsov
2017/07/23 16:55:33
Increase test robustness a bit.
|
return return_data |
-def get_expected_outputs(): |
+def get_expected_outputs(test_type): |
expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') |
- return get_dir_contents(expected_out_path).items() |
+ outputs = get_dir_contents(expected_out_path) |
+ for filename in list(outputs): |
+ if filename.endswith('@' + test_type): |
+ realname = filename.split('@')[0] |
+ outputs[realname] = outputs[filename] |
+ if '@' in filename: |
+ del outputs[filename] |
+ return outputs.items() |
-expected_outputs = get_expected_outputs() |
+ |
+static_expected_outputs = get_expected_outputs('static') |
+dynamic_expected_outputs = get_expected_outputs('dynamic') |
@pytest.fixture(scope='session', params=['master', None]) |
def revision(request): |
return request.param |
@pytest.fixture(scope='session') |
@@ -45,33 +54,33 @@ |
def dynamic_server(temp_site): |
args = ['python', 'runserver.py', temp_site] |
# Werkzeug is a dependency of flask which we are using for the mock api |
# however there is an issue with Werkzeug that prevents it from properly |
# handling the SIGTERM sent by p.kill() or terminate() |
# Issue: https://github.com/pallets/werkzeug/issues/58 |
p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid) |
time.sleep(0.5) |
- yield 'http://localhost:5000/root/' |
+ yield 'http://localhost:5000/en/' |
Vasily Kuznetsov
2017/07/23 16:55:33
This was producing "root" as current locale in the
|
os.killpg(os.getpgid(p.pid), signal.SIGTERM) |
@pytest.fixture(scope='session') |
def output_pages(static_output): |
return get_dir_contents(static_output) |
-@pytest.mark.parametrize('filename,expected_output', expected_outputs) |
+@pytest.mark.parametrize('filename,expected_output', static_expected_outputs) |
def test_static(output_pages, filename, expected_output): |
assert output_pages[filename] == expected_output |
-@pytest.mark.parametrize('filename,expected_output', expected_outputs) |
+@pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
def test_dynamic(dynamic_server, filename, expected_output): |
response = urllib2.urlopen(dynamic_server + filename) |
- assert response.read() == expected_output |
+ assert response.read().strip() == expected_output |
def test_revision_arg(revision, output_pages): |
if revision is None: |
assert 'bar' in output_pages |
else: |
assert 'bar' not in output_pages |