Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 import os | |
2 import sys | |
3 import shutil | |
4 import time | |
5 import runpy | |
6 import pytest | |
7 import urllib2 | |
8 import subprocess | |
9 | |
10 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
11 | |
12 | |
13 def get_dir_contents(path): | |
14 return_data = {} | |
15 for dirpath, dirnames, filenames in os.walk(path): | |
16 for output_file in filenames: | |
17 with open(os.path.join(dirpath, output_file)) as f: | |
18 return_data[output_file] = f.read() | |
Vasily Kuznetsov
2016/07/14 12:14:00
Is it intentional that we ignore the directory her
Jon Sonesen
2016/07/18 14:48:28
The reason we are ignoring the directories is beca
| |
19 return return_data | |
20 | |
21 | |
22 def get_expected_outputs(): | |
23 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') | |
24 return get_dir_contents(expected_out_path).items() | |
25 | |
26 expected_outputs = get_expected_outputs() | |
27 | |
28 | |
29 @pytest.fixture(scope='session') | |
30 def temp_site(tmpdir_factory): | |
31 out_dir = tmpdir_factory.mktemp('temp_out') | |
32 site_dir = out_dir.join('test_site').strpath | |
33 | |
34 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) | |
35 subprocess.check_call(['hg', 'init', site_dir]) | |
36 subprocess.check_call(['hg', '-R', site_dir, 'commit', '-A', '-m', 'foo']) | |
37 return site_dir | |
38 | |
39 | |
40 @pytest.fixture(scope='session') | |
41 def static_output(request, temp_site): | |
42 static_out_path = os.path.join(temp_site, 'static_out') | |
43 sys.argv = ['filler', temp_site, static_out_path] | |
44 | |
45 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') | |
46 return static_out_path | |
47 | |
48 | |
49 @pytest.yield_fixture(scope='session') | |
50 def dynamic_server(temp_site): | |
51 p = subprocess.Popen(['python', 'runserver.py', temp_site]) | |
52 time.sleep(0.5) | |
53 yield 'http://localhost:5000/root/' | |
54 p.terminate() | |
55 | |
56 | |
57 @pytest.fixture(scope='session') | |
58 def output_pages(static_output): | |
59 return get_dir_contents(static_output) | |
60 | |
61 | |
62 @pytest.mark.parametrize('filename,expected_output', expected_outputs) | |
63 def test_static(output_pages, filename, expected_output): | |
64 assert output_pages[filename] == expected_output | |
65 | |
66 | |
67 @pytest.mark.parametrize('filename,expected_output', expected_outputs) | |
68 def test_dynamic(dynamic_server, filename, expected_output): | |
69 response = urllib2.urlopen(dynamic_server + filename) | |
70 assert response.read() == expected_output | |
OLD | NEW |