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

Delta Between Two Patch Sets: tests/test_page_outputs.py

Issue 29400555: Issue 4992 - Adds optional revision arg to generate_static_pages (Closed) Base URL: https://hg.adblockplus.org/cms
Left Patch Set: add test coverage for static generation without the optional argument '-r/--rev' Created April 3, 2017, 10:11 a.m.
Right Patch Set: fixed redundant sys.argv definition Created April 4, 2017, 6:59 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « tests/conftest.py ('k') | tests/test_site/templates/default.tmpl » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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+'master', 36 sys.argv = ['filler', temp_site, static_out_path]
32 '--rev', 'master'] 37 if revision is not None:
38 sys.argv += ['--rev', revision]
39
33 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 40 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
34 sys.argv = ['filler', temp_site, static_out_path+'default'] 41 return static_out_path
35 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
36 return static_out_path + 'master', static_out_path + 'default'
37 42
38 43
39 @pytest.yield_fixture() 44 @pytest.yield_fixture()
40 def dynamic_server(temp_site): 45 def dynamic_server(temp_site):
41 args = ['python', 'runserver.py', temp_site] 46 args = ['python', 'runserver.py', temp_site]
42 # 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
43 # 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
44 # handling the SIGTERM sent by p.kill() or terminate() 49 # handling the SIGTERM sent by p.kill() or terminate()
45 # Issue: https://github.com/pallets/werkzeug/issues/58 50 # Issue: https://github.com/pallets/werkzeug/issues/58
46 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid) 51 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
47 time.sleep(0.5) 52 time.sleep(0.5)
48 yield 'http://localhost:5000/root/' 53 yield 'http://localhost:5000/root/'
49 os.killpg(os.getpgid(p.pid), signal.SIGTERM) 54 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
50 55
51 56
52 @pytest.fixture(scope='session') 57 @pytest.fixture(scope='session')
53 def output_pages(static_output): 58 def output_pages(static_output):
54 return (get_dir_contents(static_output[0]), 59 return get_dir_contents(static_output)
55 get_dir_contents(static_output[1]))
56 60
57 61
58 @pytest.mark.parametrize('filename,expected_output', expected_outputs) 62 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
59 def test_static(output_pages, filename, expected_output): 63 def test_static(output_pages, filename, expected_output):
60 assert output_pages[0][filename] == expected_output 64 assert output_pages[filename] == expected_output
61 assert output_pages[1][filename] == expected_output
62 65
63 66
64 @pytest.mark.parametrize('filename,expected_output', expected_outputs) 67 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
65 def test_dynamic(dynamic_server, filename, expected_output): 68 def test_dynamic(dynamic_server, filename, expected_output):
66 response = urllib2.urlopen(dynamic_server + filename) 69 response = urllib2.urlopen(dynamic_server + filename)
67 assert response.read() == expected_output 70 assert response.read() == expected_output
68 71
69 72
70 def test_revision_arg(output_pages): 73 def test_revision_arg(revision, output_pages):
71 assert 'bar' not in output_pages[0] 74 if revision is None:
75 assert 'bar' in output_pages
76 else:
77 assert 'bar' not in output_pages
LEFTRIGHT

Powered by Google App Engine
This is Rietveld