Index: tests/test_page_outputs.py |
=================================================================== |
--- a/tests/test_page_outputs.py |
+++ b/tests/test_page_outputs.py |
@@ -9,25 +9,36 @@ |
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() |
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): |
+ # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") |
Vasily Kuznetsov
2017/08/03 09:12:20
I added a comment to make it more clear what's goi
|
+ # and remove the expected outputs that don't apply for this test type. |
+ 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 +56,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/' |
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 |