Left: | ||
Right: |
OLD | NEW |
---|---|
1 import logging | |
1 import os | 2 import os |
2 import sys | 3 import sys |
3 import runpy | 4 import runpy |
4 | 5 |
5 import mock | 6 import mock |
6 import pytest | 7 import pytest |
7 | 8 |
8 from .conftest import ROOTPATH | 9 from .conftest import ROOTPATH |
9 from .utils import get_dir_contents, exception_test | 10 from .utils import get_dir_contents, exception_test |
10 from cms.sources import FileSource | 11 from cms.sources import FileSource |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 assert filename not in output_pages_relative | 59 assert filename not in output_pages_relative |
59 else: | 60 else: |
60 assert expected_output == output_pages_relative[filename] | 61 assert expected_output == output_pages_relative[filename] |
61 | 62 |
62 | 63 |
63 def test_cache(output_pages): | 64 def test_cache(output_pages): |
64 source = FileSource(os.path.join('test_site')) | 65 source = FileSource(os.path.join('test_site')) |
65 assert source.get_cache_dir() == os.path.join('test_site', 'cache') | 66 assert source.get_cache_dir() == os.path.join('test_site', 'cache') |
66 | 67 |
67 | 68 |
69 def test_broken_link_warnings(temp_site, tmpdir_factory, caplog): | |
70 caplog.set_level(logging.WARNING) | |
71 generate_static_pages(temp_site, tmpdir_factory) | |
72 messages = {t[2] for t in caplog.record_tuples} | |
73 expected_messages = [ | |
74 'Link to "missing" (from "brokenlink") cannot be resolved', | |
75 'Link to "missing" (from "brokenlink-html") cannot be resolved', | |
76 'Link to "missing" (from "brokenlink-tmpl") cannot be resolved', | |
77 ] | |
78 for message in expected_messages: | |
79 assert message in messages | |
rhowell
2019/04/12 20:17:12
NIT: This test might be a bit stricter if we used
Vasily Kuznetsov
2019/04/15 16:48:45
Yes, I thought about it too. In the end I decided
rhowell
2019/04/16 01:46:58
Makes sense.
| |
80 | |
81 | |
68 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) | 82 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
69 def test_dynamic_server_handler(filename, expected_output, temp_site): | 83 def test_dynamic_server_handler(filename, expected_output, temp_site): |
70 | 84 |
71 def cleanup(page): | 85 def cleanup(page): |
72 return page.replace(os.linesep, '').strip() | 86 return page.replace(os.linesep, '').strip() |
73 | 87 |
74 handler = DynamicServerHandler('localhost', 5000, str(temp_site)) | 88 handler = DynamicServerHandler('localhost', 5000, str(temp_site)) |
75 environ = {'PATH_INFO': filename} | 89 environ = {'PATH_INFO': filename} |
76 | 90 |
77 generated_page = handler(environ, lambda x, y: None) | 91 generated_page = handler(environ, lambda x, y: None) |
78 | 92 |
79 assert cleanup(expected_output) == cleanup(generated_page[0]) | 93 assert cleanup(expected_output) == cleanup(generated_page[0]) |
80 | 94 |
81 | 95 |
82 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) | 96 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) |
83 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): | 97 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): |
84 handler = DynamicServerHandler('localhost', 5000, | 98 handler = DynamicServerHandler('localhost', 5000, |
85 str(temp_site_with_conflicts)) | 99 str(temp_site_with_conflicts)) |
86 environ = {'PATH_INFO': page} | 100 environ = {'PATH_INFO': page} |
87 exp_msg = 'The requested page conflicts with another page.' | 101 exp_msg = 'The requested page conflicts with another page.' |
88 | 102 |
89 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) | 103 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) |
OLD | NEW |