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

Unified 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.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cms/sources.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/test_additional_paths.py
===================================================================
--- a/tests/test_additional_paths.py
+++ b/tests/test_additional_paths.py
@@ -25,68 +25,82 @@
from .utils import get_dir_contents, run_test_server
PATHS_FRAGMENT_TEMPLATE = """
[paths]
additional-paths = {}
"""
+# Expected strings in CMS output:
+EXPECTATIONS = [
+ # Pages from the main site have priority.
+ ('en/filter', 'MAIN_SITE'),
+ # Lists of pages from main website and additional paths are merged.
+ ('en/map', 'sitemap'),
+ ('en/sitemap', 'map'),
+ # Pages that have same name but different extensions on main website and
+ # additional paths are handled correctly (no conflict and main website
+ # should have priority, see https://issues.adblockplus.org/ticket/5862)
+ ('en/global', 'MAIN_SITE'),
+ ('en/translate', 'MAIN_SITE'),
+]
+
@pytest.fixture(scope='session')
def ap_site(temp_site, tmpdir_factory):
"""A website source that has another website in additional-paths."""
base_root = py.path.local(temp_site)
base_pages = base_root.join('pages')
ap_root = tmpdir_factory.mktemp('ap_site')
ap_root.join('settings.ini').write(
base_root.join('settings.ini').read() +
PATHS_FRAGMENT_TEMPLATE.format(base_root)
)
pages = ap_root.mkdir('pages')
- pages.join('filter.tmpl').write(base_pages.join('filter.tmpl').read() +
- 'MARKER')
+ for file_name in ['filter.tmpl', 'global.md', 'translate.tmpl']:
+ pages.join(file_name).write('template=empty\n\nMAIN_SITE')
pages.join('map.tmpl').write(base_pages.join('sitemap.tmpl').read())
subprocess.check_call(['hg', 'init', ap_root.strpath])
subprocess.check_call(['hg', '-R', ap_root.strpath,
'commit', '-A', '-m', 'foo'])
return ap_root
@pytest.fixture(scope='session')
def ap_static_output(tmpdir_factory, ap_site):
"""Generate website from two source directories, return output path."""
out_path = tmpdir_factory.mktemp('ap_out')
saved_argv = sys.argv
sys.argv = ['', ap_site.strpath, out_path.strpath]
runpy.run_module('cms.bin.generate_static_pages', run_name='__main__')
- yield out_path
+ yield get_dir_contents(out_path.strpath)
sys.argv = saved_argv
-def test_ap_static(ap_static_output):
- outfiles = get_dir_contents(ap_static_output.strpath)
- assert outfiles['en/filter'].endswith('MARKER') # We can override pages.
- assert 'sitemap' in outfiles['en/map'] # The lists of pages are
- assert 'map' in outfiles['en/sitemap'] # merged.
-
-
@pytest.fixture(scope='module')
def dynamic_server(ap_site):
+ """Run CMS test server and returns its URL."""
with run_test_server(ap_site.strpath) as ts:
yield ts
-def test_dynamic(dynamic_server):
- response = urllib2.urlopen(dynamic_server + 'en/filter')
- assert response.read().endswith('MARKER')
+@pytest.mark.parametrize('page_name,expectation', EXPECTATIONS)
+def test_ap_static(ap_static_output, page_name, expectation):
+ assert expectation in ap_static_output[page_name]
+
+
+@pytest.mark.parametrize('page_name,expectation', EXPECTATIONS)
+def test_dynamic(dynamic_server, page_name, expectation):
+ response = urllib2.urlopen(dynamic_server + page_name)
+ assert expectation in response.read()
def test_create_source(tmpdir):
"""Create a hierarchy of multi-sources testing different config options."""
one = tmpdir.mkdir('one')
two = tmpdir.mkdir('two')
three = tmpdir.mkdir('three')
four = two.mkdir('four')
« 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