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

Side by Side Diff: 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
Patch Set: removes duplication in fixtures and addresses arg message changes Created April 3, 2017, 2:40 p.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/conftest.py ('k') | tests/test_site/templates/default.tmpl » ('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 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 if revision is None:
Vasily Kuznetsov 2017/04/03 15:15:52 We don't really need to repeat the standard args t
Jon Sonesen 2017/04/04 07:01:23 Done.
37 sys.argv = ['filler', temp_site, static_out_path]
38 else:
39 sys.argv = ['filler', temp_site, static_out_path, '--rev', 'master']
Vasily Kuznetsov 2017/04/03 15:15:52 The last item of the list should be `revision` but
Jon Sonesen 2017/04/04 07:01:23 Done.
40
32 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 41 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
33 return static_out_path 42 return static_out_path
34 43
35 44
36 @pytest.yield_fixture() 45 @pytest.yield_fixture()
37 def dynamic_server(temp_site): 46 def dynamic_server(temp_site):
38 args = ['python', 'runserver.py', temp_site] 47 args = ['python', 'runserver.py', temp_site]
39 # Werkzeug is a dependency of flask which we are using for the mock api 48 # 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 49 # however there is an issue with Werkzeug that prevents it from properly
41 # handling the SIGTERM sent by p.kill() or terminate() 50 # handling the SIGTERM sent by p.kill() or terminate()
(...skipping 11 matching lines...) Expand all
53 62
54 @pytest.mark.parametrize('filename,expected_output', expected_outputs) 63 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
55 def test_static(output_pages, filename, expected_output): 64 def test_static(output_pages, filename, expected_output):
56 assert output_pages[filename] == expected_output 65 assert output_pages[filename] == expected_output
57 66
58 67
59 @pytest.mark.parametrize('filename,expected_output', expected_outputs) 68 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
60 def test_dynamic(dynamic_server, filename, expected_output): 69 def test_dynamic(dynamic_server, filename, expected_output):
61 response = urllib2.urlopen(dynamic_server + filename) 70 response = urllib2.urlopen(dynamic_server + filename)
62 assert response.read() == expected_output 71 assert response.read() == expected_output
72
73
74 def test_revision_arg(revision, output_pages):
75 if revision is None:
76 assert 'bar' in output_pages
77 else:
78 assert 'bar' not in output_pages
OLDNEW
« no previous file with comments | « tests/conftest.py ('k') | tests/test_site/templates/default.tmpl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld