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: add test coverage for static generation without the optional argument '-r/--rev' Created April 3, 2017, 10:11 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/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
(...skipping 10 matching lines...) Expand all
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') 28 @pytest.fixture(scope='session')
29 def static_output(request, temp_site): 29 def static_output(request, temp_site):
30 static_out_path = os.path.join(temp_site, 'static_out') 30 static_out_path = os.path.join(temp_site, 'static_out')
31 sys.argv = ['filler', temp_site, static_out_path] 31 sys.argv = ['filler', temp_site, static_out_path+'master',
32 '--rev', 'master']
32 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 33 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
33 return static_out_path 34 sys.argv = ['filler', temp_site, static_out_path+'default']
35 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
36 return static_out_path + 'master', static_out_path + 'default'
34 37
35 38
36 @pytest.yield_fixture() 39 @pytest.yield_fixture()
37 def dynamic_server(temp_site): 40 def dynamic_server(temp_site):
38 args = ['python', 'runserver.py', temp_site] 41 args = ['python', 'runserver.py', temp_site]
39 # Werkzeug is a dependency of flask which we are using for the mock api 42 # 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 43 # however there is an issue with Werkzeug that prevents it from properly
41 # handling the SIGTERM sent by p.kill() or terminate() 44 # handling the SIGTERM sent by p.kill() or terminate()
42 # Issue: https://github.com/pallets/werkzeug/issues/58 45 # Issue: https://github.com/pallets/werkzeug/issues/58
43 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid) 46 p = subprocess.Popen(args, stdout=subprocess.PIPE, preexec_fn=os.setsid)
44 time.sleep(0.5) 47 time.sleep(0.5)
45 yield 'http://localhost:5000/root/' 48 yield 'http://localhost:5000/root/'
46 os.killpg(os.getpgid(p.pid), signal.SIGTERM) 49 os.killpg(os.getpgid(p.pid), signal.SIGTERM)
47 50
48 51
49 @pytest.fixture(scope='session') 52 @pytest.fixture(scope='session')
50 def output_pages(static_output): 53 def output_pages(static_output):
51 return get_dir_contents(static_output) 54 return (get_dir_contents(static_output[0]),
55 get_dir_contents(static_output[1]))
52 56
53 57
54 @pytest.mark.parametrize('filename,expected_output', expected_outputs) 58 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
55 def test_static(output_pages, filename, expected_output): 59 def test_static(output_pages, filename, expected_output):
56 assert output_pages[filename] == expected_output 60 assert output_pages[0][filename] == expected_output
61 assert output_pages[1][filename] == expected_output
57 62
58 63
59 @pytest.mark.parametrize('filename,expected_output', expected_outputs) 64 @pytest.mark.parametrize('filename,expected_output', expected_outputs)
60 def test_dynamic(dynamic_server, filename, expected_output): 65 def test_dynamic(dynamic_server, filename, expected_output):
61 response = urllib2.urlopen(dynamic_server + filename) 66 response = urllib2.urlopen(dynamic_server + filename)
62 assert response.read() == expected_output 67 assert response.read() == expected_output
68
69
70 def test_revision_arg(output_pages):
71 assert 'bar' not in output_pages[0]
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