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

Side by Side Diff: tests/test_additional_paths.py

Issue 29586663: Fixes 5862 - Prevent page conflicts caused by additional-paths (Closed)
Patch Set: Created Oct. 23, 2017, 3:31 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 | « cms/sources.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 12 matching lines...) Expand all
23 23
24 from cms.sources import create_source 24 from cms.sources import create_source
25 from .utils import get_dir_contents, run_test_server 25 from .utils import get_dir_contents, run_test_server
26 26
27 27
28 PATHS_FRAGMENT_TEMPLATE = """ 28 PATHS_FRAGMENT_TEMPLATE = """
29 [paths] 29 [paths]
30 additional-paths = {} 30 additional-paths = {}
31 """ 31 """
32 32
33 # Expected strings in CMS output:
34 EXPECTATIONS = [
35 # Pages from the main site have priority.
36 ('en/filter', 'MAIN_SITE'),
37 # Lists of pages from main website and additional paths are merged.
38 ('en/map', 'sitemap'),
39 ('en/sitemap', 'map'),
40 # Pages that have same name but different extensions on main website and
41 # additional paths are handled correctly (no conflict and main website
42 # should have priority, see https://issues.adblockplus.org/ticket/5862)
43 ('en/global', 'MAIN_SITE'),
44 ('en/translate', 'MAIN_SITE'),
45 ]
46
33 47
34 @pytest.fixture(scope='session') 48 @pytest.fixture(scope='session')
35 def ap_site(temp_site, tmpdir_factory): 49 def ap_site(temp_site, tmpdir_factory):
36 """A website source that has another website in additional-paths.""" 50 """A website source that has another website in additional-paths."""
37 base_root = py.path.local(temp_site) 51 base_root = py.path.local(temp_site)
38 base_pages = base_root.join('pages') 52 base_pages = base_root.join('pages')
39 53
40 ap_root = tmpdir_factory.mktemp('ap_site') 54 ap_root = tmpdir_factory.mktemp('ap_site')
41 ap_root.join('settings.ini').write( 55 ap_root.join('settings.ini').write(
42 base_root.join('settings.ini').read() + 56 base_root.join('settings.ini').read() +
43 PATHS_FRAGMENT_TEMPLATE.format(base_root) 57 PATHS_FRAGMENT_TEMPLATE.format(base_root)
44 ) 58 )
45 59
46 pages = ap_root.mkdir('pages') 60 pages = ap_root.mkdir('pages')
47 pages.join('filter.tmpl').write(base_pages.join('filter.tmpl').read() + 61 for file_name in ['filter.tmpl', 'global.md', 'translate.tmpl']:
48 'MARKER') 62 pages.join(file_name).write('template=empty\n\nMAIN_SITE')
49 pages.join('map.tmpl').write(base_pages.join('sitemap.tmpl').read()) 63 pages.join('map.tmpl').write(base_pages.join('sitemap.tmpl').read())
50 64
51 subprocess.check_call(['hg', 'init', ap_root.strpath]) 65 subprocess.check_call(['hg', 'init', ap_root.strpath])
52 subprocess.check_call(['hg', '-R', ap_root.strpath, 66 subprocess.check_call(['hg', '-R', ap_root.strpath,
53 'commit', '-A', '-m', 'foo']) 67 'commit', '-A', '-m', 'foo'])
54 68
55 return ap_root 69 return ap_root
56 70
57 71
58 @pytest.fixture(scope='session') 72 @pytest.fixture(scope='session')
59 def ap_static_output(tmpdir_factory, ap_site): 73 def ap_static_output(tmpdir_factory, ap_site):
60 """Generate website from two source directories, return output path.""" 74 """Generate website from two source directories, return output path."""
61 out_path = tmpdir_factory.mktemp('ap_out') 75 out_path = tmpdir_factory.mktemp('ap_out')
62 saved_argv = sys.argv 76 saved_argv = sys.argv
63 sys.argv = ['', ap_site.strpath, out_path.strpath] 77 sys.argv = ['', ap_site.strpath, out_path.strpath]
64 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__') 78 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
65 yield out_path 79 yield get_dir_contents(out_path.strpath)
66 sys.argv = saved_argv 80 sys.argv = saved_argv
67 81
68 82
69 def test_ap_static(ap_static_output):
70 outfiles = get_dir_contents(ap_static_output.strpath)
71 assert outfiles['en/filter'].endswith('MARKER') # We can override pages.
72 assert 'sitemap' in outfiles['en/map'] # The lists of pages are
73 assert 'map' in outfiles['en/sitemap'] # merged.
74
75
76 @pytest.fixture(scope='module') 83 @pytest.fixture(scope='module')
77 def dynamic_server(ap_site): 84 def dynamic_server(ap_site):
85 """Run CMS test server and returns its URL."""
78 with run_test_server(ap_site.strpath) as ts: 86 with run_test_server(ap_site.strpath) as ts:
79 yield ts 87 yield ts
80 88
81 89
82 def test_dynamic(dynamic_server): 90 @pytest.mark.parametrize('page_name,expectation', EXPECTATIONS)
83 response = urllib2.urlopen(dynamic_server + 'en/filter') 91 def test_ap_static(ap_static_output, page_name, expectation):
84 assert response.read().endswith('MARKER') 92 assert expectation in ap_static_output[page_name]
93
94
95 @pytest.mark.parametrize('page_name,expectation', EXPECTATIONS)
96 def test_dynamic(dynamic_server, page_name, expectation):
97 response = urllib2.urlopen(dynamic_server + page_name)
98 assert expectation in response.read()
85 99
86 100
87 def test_create_source(tmpdir): 101 def test_create_source(tmpdir):
88 """Create a hierarchy of multi-sources testing different config options.""" 102 """Create a hierarchy of multi-sources testing different config options."""
89 one = tmpdir.mkdir('one') 103 one = tmpdir.mkdir('one')
90 two = tmpdir.mkdir('two') 104 two = tmpdir.mkdir('two')
91 three = tmpdir.mkdir('three') 105 three = tmpdir.mkdir('three')
92 four = two.mkdir('four') 106 four = two.mkdir('four')
93 107
94 one_ap = '\n {}\n {}'.format(two.strpath, '../three') 108 one_ap = '\n {}\n {}'.format(two.strpath, '../three')
95 one.join('settings.ini').write(PATHS_FRAGMENT_TEMPLATE.format(one_ap)) 109 one.join('settings.ini').write(PATHS_FRAGMENT_TEMPLATE.format(one_ap))
96 one.join('one').write('') 110 one.join('one').write('')
97 111
98 two.join('settings.ini').write(PATHS_FRAGMENT_TEMPLATE.format('four')) 112 two.join('settings.ini').write(PATHS_FRAGMENT_TEMPLATE.format('four'))
99 two.join('two').write('') 113 two.join('two').write('')
100 114
101 three.join('three').write('') 115 three.join('three').write('')
102 three.join('settings.ini').write('') 116 three.join('settings.ini').write('')
103 117
104 four.join('four').write('') 118 four.join('four').write('')
105 four.join('settings.ini').write('[paths]') 119 four.join('settings.ini').write('[paths]')
106 120
107 source = create_source(one.strpath) 121 source = create_source(one.strpath)
108 122
109 for name in ['one', 'two', 'three', 'four']: 123 for name in ['one', 'two', 'three', 'four']:
110 assert source.has_file(name) 124 assert source.has_file(name)
OLDNEW
« no previous file with comments | « cms/sources.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld