LEFT | RIGHT |
(no file at all) | |
| 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 from "brokenlink" to "missing" cannot be resolved', |
| 75 'Link from "brokenlink-html" to "missing" cannot be resolved', |
| 76 'Link from "brokenlink-tmpl" to "missing" cannot be resolved', |
| 77 ] |
| 78 for message in expected_messages: |
| 79 assert message in messages |
| 80 raise messages |
| 81 |
| 82 |
68 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) | 83 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
69 def test_dynamic_server_handler(filename, expected_output, temp_site): | 84 def test_dynamic_server_handler(filename, expected_output, temp_site): |
70 | 85 |
71 def cleanup(page): | 86 def cleanup(page): |
72 return page.replace(os.linesep, '').strip() | 87 return page.replace(os.linesep, '').strip() |
73 | 88 |
74 handler = DynamicServerHandler('localhost', 5000, str(temp_site)) | 89 handler = DynamicServerHandler('localhost', 5000, str(temp_site)) |
75 environ = {'PATH_INFO': filename} | 90 environ = {'PATH_INFO': filename} |
76 | 91 |
77 generated_page = handler(environ, lambda x, y: None) | 92 generated_page = handler(environ, lambda x, y: None) |
78 | 93 |
79 assert cleanup(expected_output) == cleanup(generated_page[0]) | 94 assert cleanup(expected_output) == cleanup(generated_page[0]) |
80 | 95 |
81 | 96 |
82 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) | 97 @pytest.mark.parametrize('page', ['en/translate', '/en/translate']) |
83 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): | 98 def test_dynamic_server_handler_with_conflicts(page, temp_site_with_conflicts): |
84 handler = DynamicServerHandler('localhost', 5000, | 99 handler = DynamicServerHandler('localhost', 5000, |
85 str(temp_site_with_conflicts)) | 100 str(temp_site_with_conflicts)) |
86 environ = {'PATH_INFO': page} | 101 environ = {'PATH_INFO': page} |
87 exp_msg = 'The requested page conflicts with another page.' | 102 exp_msg = 'The requested page conflicts with another page.' |
88 | 103 |
89 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) | 104 exception_test(handler, Exception, exp_msg, environ, lambda x, y: None) |
LEFT | RIGHT |