OLD | NEW |
1 import os | 1 import os |
2 import sys | 2 import sys |
3 import time | 3 import time |
4 import runpy | 4 import runpy |
5 import signal | 5 import signal |
6 import pytest | 6 import pytest |
7 import urllib2 | 7 import urllib2 |
8 import subprocess | 8 import subprocess |
9 from conftest import ROOTPATH | 9 from conftest import ROOTPATH |
10 | 10 |
11 | 11 |
12 def get_dir_contents(path): | 12 def get_dir_contents(path): |
13 return_data = {} | 13 return_data = {} |
14 for dirpath, dirnames, filenames in os.walk(path): | 14 for dirpath, dirnames, filenames in os.walk(path): |
15 for output_file in filenames: | 15 for output_file in filenames: |
16 with open(os.path.join(dirpath, output_file)) as f: | 16 with open(os.path.join(dirpath, output_file)) as f: |
17 return_data[output_file] = f.read() | 17 return_data[output_file] = f.read() |
18 return return_data | 18 return return_data |
19 | 19 |
20 | 20 |
21 def get_expected_outputs(): | 21 def get_expected_outputs(): |
22 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') | 22 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') |
23 return get_dir_contents(expected_out_path).items() | 23 return get_dir_contents(expected_out_path).items() |
24 | 24 |
25 expected_outputs = get_expected_outputs() | 25 expected_outputs = get_expected_outputs() |
26 | 26 |
27 | 27 |
| 28 @pytest.fixture(scope='session', params=['master', None]) |
| 29 def revision(request): |
| 30 return request.param |
| 31 |
| 32 |
28 @pytest.fixture(scope='session') | 33 @pytest.fixture(scope='session') |
29 def static_output(request, temp_site): | 34 def static_output(revision, request, temp_site): |
30 static_out_path = os.path.join(temp_site, 'static_out') | 35 static_out_path = os.path.join(temp_site, 'static_out') |
31 sys.argv = ['filler', temp_site, static_out_path] | 36 sys.argv = ['filler', temp_site, static_out_path] |
| 37 if revision is not None: |
| 38 sys.argv += ['--rev', revision] |
| 39 |
32 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') | 40 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') |
33 return static_out_path | 41 return static_out_path |
34 | 42 |
35 | 43 |
36 @pytest.yield_fixture() | 44 @pytest.yield_fixture() |
37 def dynamic_server(temp_site): | 45 def dynamic_server(temp_site): |
38 args = ['python', 'runserver.py', temp_site] | 46 args = ['python', 'runserver.py', temp_site] |
39 # Werkzeug is a dependency of flask which we are using for the mock api | 47 # Werkzeug is a dependency of flask which we are using for the mock api |
40 # however there is an issue with Werkzeug that prevents it from properly | 48 # however there is an issue with Werkzeug that prevents it from properly |
41 # handling the SIGTERM sent by p.kill() or terminate() | 49 # handling the SIGTERM sent by p.kill() or terminate() |
(...skipping 11 matching lines...) Expand all Loading... |
53 | 61 |
54 @pytest.mark.parametrize('filename,expected_output', expected_outputs) | 62 @pytest.mark.parametrize('filename,expected_output', expected_outputs) |
55 def test_static(output_pages, filename, expected_output): | 63 def test_static(output_pages, filename, expected_output): |
56 assert output_pages[filename] == expected_output | 64 assert output_pages[filename] == expected_output |
57 | 65 |
58 | 66 |
59 @pytest.mark.parametrize('filename,expected_output', expected_outputs) | 67 @pytest.mark.parametrize('filename,expected_output', expected_outputs) |
60 def test_dynamic(dynamic_server, filename, expected_output): | 68 def test_dynamic(dynamic_server, filename, expected_output): |
61 response = urllib2.urlopen(dynamic_server + filename) | 69 response = urllib2.urlopen(dynamic_server + filename) |
62 assert response.read() == expected_output | 70 assert response.read() == expected_output |
| 71 |
| 72 |
| 73 def test_revision_arg(revision, output_pages): |
| 74 if revision is None: |
| 75 assert 'bar' in output_pages |
| 76 else: |
| 77 assert 'bar' not in output_pages |
OLD | NEW |