Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: tests/test_page_outputs.py

Issue 29345468: Issue 4045 - Add Test Suite To CMS (Closed)
Patch Set: fixed erroneous upload of patch Created Aug. 25, 2016, 9:04 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tests/expected_output/global ('k') | tests/test_site/filters/foo_converter.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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()
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 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
45 return static_out_path
46
47
48 @pytest.yield_fixture(scope='session')
49 def dynamic_server(temp_site):
50 p = subprocess.Popen(['python', 'runserver.py', temp_site])
51 time.sleep(0.5)
52 yield 'http://localhost:5000/root/'
53 p.terminate()
54
55
56 @pytest.fixture(scope='session')
57 def output_pages(static_output):
58 return get_dir_contents(static_output)
59
60
61 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
62 def test_static(output_pages, filename, expected_output):
63 assert output_pages[filename] == expected_output
64
65
66 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
67 def test_dynamic(dynamic_server, filename, expected_output):
68 response = urllib2.urlopen(dynamic_server + filename)
69 assert response.read() == expected_output
OLDNEW
« no previous file with comments | « tests/expected_output/global ('k') | tests/test_site/filters/foo_converter.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld