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

Side by Side Diff: tests/test_additional_paths.py

Issue 29555839: Issue 5336 - Allow additional include, page, and template paths using CMS (Closed)
Patch Set: Created Sept. 25, 2017, 7:12 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
OLDNEW
(Empty)
1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH
3 #
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
6 # published by the Free Software Foundation.
7 #
8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15
16 import subprocess
17 import sys
18 import urllib2
19
20 import py
21 import pytest
22 import runpy
23
24 from cms.sources import create_source
25 from .utils import get_dir_contents, run_test_server
26
27
28 PATHS_FRAGMENT_TEMPLATE = """
29 [paths]
30 additional-paths = {}
31 """
32
33
34 @pytest.fixture(scope='session')
35 def ap_site(temp_site, tmpdir_factory):
36 """A website source that has another website in additional-paths."""
37 base_root = py.path.local(temp_site)
38 base_pages = base_root.join('pages')
39
40 ap_root = tmpdir_factory.mktemp('ap_site')
41 ap_root.join('settings.ini').write(
42 base_root.join('settings.ini').read() +
43 PATHS_FRAGMENT_TEMPLATE.format(base_root)
44 )
45
46 pages = ap_root.mkdir('pages')
47 pages.join('filter.tmpl').write(base_pages.join('filter.tmpl').read() +
48 'MARKER')
49 pages.join('map.tmpl').write(base_pages.join('sitemap.tmpl').read())
50
51 subprocess.check_call(['hg', 'init', ap_root.strpath])
52 subprocess.check_call(['hg', '-R', ap_root.strpath,
53 'commit', '-A', '-m', 'foo'])
54
55 return ap_root
56
57
58 @pytest.fixture(scope='session')
59 def ap_static_output(tmpdir_factory, ap_site):
60 """Generate website from two source directories, return output path."""
61 out_path = tmpdir_factory.mktemp('ap_out')
62 saved_argv = sys.argv
63 sys.argv = ['', ap_site.strpath, out_path.strpath]
64 runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
65 yield out_path
66 sys.argv = saved_argv
67
68
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')
77 def dynamic_server(ap_site):
78 with run_test_server(ap_site.strpath) as ts:
79 yield ts
80
81
82 def test_dynamic(dynamic_server):
83 response = urllib2.urlopen(dynamic_server + 'en/filter')
84 assert response.read().endswith('MARKER')
85
86
87 def test_create_source(tmpdir):
88 """Create a hierarchy of multi-sources testing different config options."""
89 one = tmpdir.mkdir('one')
90 two = tmpdir.mkdir('two')
91 three = tmpdir.mkdir('three')
92 four = two.mkdir('four')
93
94 one_ap = '\n {}\n {}'.format(two.strpath, '../three')
95 one.join('settings.ini').write(PATHS_FRAGMENT_TEMPLATE.format(one_ap))
96 one.join('one').write('')
97
98 two.join('settings.ini').write(PATHS_FRAGMENT_TEMPLATE.format('four'))
99 two.join('two').write('')
100
101 three.join('three').write('')
102 three.join('settings.ini').write('')
103
104 four.join('four').write('')
105 four.join('settings.ini').write('')
106
107 source = create_source(one.strpath)
108
109 for name in ['one', 'two', 'three', 'four']:
110 assert source.has_file(name)
OLDNEW
« cms/sources.py ('K') | « tests/__init__.py ('k') | tests/test_multi_source.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld