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

Side by Side Diff: tests/test_page_outputs.py

Issue 29555839: Issue 5336 - Allow additional include, page, and template paths using CMS (Closed)
Patch Set: Rename 'static' parameter to 'cached' Created Oct. 2, 2017, 10:49 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/test_multi_source.py ('k') | tests/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import sys 2 import sys
3 import time
4 import runpy 3 import runpy
5 import signal
6 import pytest 4 import pytest
7 import urllib2 5 import urllib2
8 import subprocess
9 from conftest import ROOTPATH
10 6
11 7 from .conftest import ROOTPATH
12 def get_dir_contents(path): 8 from .utils import get_dir_contents, run_test_server
13 dirdata = {}
14 for dirpath, dirnames, filenames in os.walk(path):
15 for output_file in filenames:
16 filepath = os.path.join(dirpath, output_file)
17 with open(filepath) as f:
18 locale = os.path.split(os.path.split(filepath)[0])[1]
19 dirdata[os.path.join(locale, output_file)] = f.read().strip()
20 return dirdata
21 9
22 10
23 def get_expected_outputs(test_type): 11 def get_expected_outputs(test_type):
24 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') 12 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output')
25 outputs = get_dir_contents(expected_out_path) 13 outputs = get_dir_contents(expected_out_path)
26 for filename in list(outputs): 14 for filename in list(outputs):
27 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") 15 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz")
28 # and remove the expected outputs that don't apply for this test type. 16 # and remove the expected outputs that don't apply for this test type.
29 if filename.endswith('@' + test_type): 17 if filename.endswith('@' + test_type):
30 realname = filename.split('@')[0] 18 realname = filename.split('@')[0]
(...skipping 16 matching lines...) Expand all
47 def static_output(revision, request, temp_site): 35 def static_output(revision, request, temp_site):
48 static_out_path = os.path.join(temp_site, 'static_out') 36 static_out_path = os.path.join(temp_site, 'static_out')
49 sys.argv = ['filler', temp_site, static_out_path] 37 sys.argv = ['filler', temp_site, static_out_path]
50 if revision is not None: 38 if revision is not None:
51 sys.argv += ['--rev', revision] 39 sys.argv += ['--rev', revision]
52 40
53 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 41 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
54 return static_out_path 42 return static_out_path
55 43
56 44
57 @pytest.yield_fixture() 45 @pytest.fixture(scope='module')
58 def dynamic_server(temp_site): 46 def dynamic_server(temp_site):
59 args = ['python', 'runserver.py', temp_site] 47 with run_test_server(temp_site) as ts:
60 # Werkzeug is a dependency of flask which we are using for the mock api 48 yield ts
61 # however there is an issue with Werkzeug that prevents it from properly
62 # handling the SIGTERM sent by p.kill() or terminate()
63 # Issue: https://github.com/pallets/werkzeug/issues/58
64 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
65 time.sleep(0.5)
66 yield 'http://localhost:5000/'
67 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
68 49
69 50
70 @pytest.fixture(scope='session') 51 @pytest.fixture(scope='session')
71 def output_pages(static_output): 52 def output_pages(static_output):
72 return get_dir_contents(static_output) 53 return get_dir_contents(static_output)
73 54
74 55
75 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) 56 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs)
76 def test_static(output_pages, filename, expected_output): 57 def test_static(output_pages, filename, expected_output):
77 assert output_pages[filename] == expected_output 58 assert output_pages[filename] == expected_output
78 59
79 60
80 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) 61 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs)
81 def test_dynamic(dynamic_server, filename, expected_output): 62 def test_dynamic(dynamic_server, filename, expected_output):
82 response = urllib2.urlopen(dynamic_server + filename) 63 response = urllib2.urlopen(dynamic_server + filename)
83 assert response.read().strip() == expected_output 64 assert response.read().strip() == expected_output
84 65
85 66
86 def test_revision_arg(revision, output_pages): 67 def test_revision_arg(revision, output_pages):
87 if revision is None: 68 if revision is None:
88 assert 'en/bar' in output_pages 69 assert 'en/bar' in output_pages
89 else: 70 else:
90 assert 'en/bar' not in output_pages 71 assert 'en/bar' not in output_pages
OLDNEW
« no previous file with comments | « tests/test_multi_source.py ('k') | tests/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld