LEFT | RIGHT |
1 import os | 1 import os |
2 import sys | 2 import sys |
3 import runpy | 3 import runpy |
4 | 4 |
5 import mock | 5 import mock |
6 import pytest | 6 import pytest |
7 import urllib2 | 7 import urllib2 |
8 | 8 |
9 from .conftest import ROOTPATH | 9 from .conftest import ROOTPATH |
10 from .utils import get_dir_contents, run_test_server | 10 from .utils import get_dir_contents, run_test_server |
| 11 from cms.sources import FileSource |
11 | 12 |
12 | 13 |
13 def get_expected_outputs(test_type): | 14 def get_expected_outputs(test_type): |
14 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') | 15 expected_out_path = os.path.join(ROOTPATH, 'tests', 'expected_output') |
15 outputs = get_dir_contents(expected_out_path) | 16 outputs = get_dir_contents(expected_out_path) |
16 for filename in list(outputs): | 17 for filename in list(outputs): |
17 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") | 18 # Move test-type-specific expected outputs (e.g. "xyz@static" -> "xyz") |
18 # There are cases where we need to test outputs which differ depending | 19 # There are cases where we need to test outputs which differ depending |
19 # on how they are generated; either statically or dynamically | 20 # on how they are generated; either statically or dynamically |
20 if filename.endswith('@' + test_type): | 21 if filename.endswith('@' + test_type): |
(...skipping 27 matching lines...) Expand all Loading... |
48 | 49 |
49 @pytest.fixture(scope='session') | 50 @pytest.fixture(scope='session') |
50 def output_pages(static_output): | 51 def output_pages(static_output): |
51 return get_dir_contents(static_output) | 52 return get_dir_contents(static_output) |
52 | 53 |
53 | 54 |
54 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) | 55 @pytest.mark.parametrize('filename,expected_output', static_expected_outputs) |
55 def test_static(output_pages, filename, expected_output): | 56 def test_static(output_pages, filename, expected_output): |
56 if expected_output.startswith('## MISSING'): | 57 if expected_output.startswith('## MISSING'): |
57 assert filename not in output_pages | 58 assert filename not in output_pages |
58 return | 59 else: |
59 assert expected_output == output_pages[filename] | 60 assert expected_output == output_pages[filename] |
60 | 61 |
61 | 62 |
62 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) | 63 @pytest.mark.parametrize('filename,expected_output', dynamic_expected_outputs) |
63 def test_dynamic(dynamic_server, filename, expected_output): | 64 def test_dynamic(dynamic_server, filename, expected_output): |
64 response = urllib2.urlopen(dynamic_server + filename) | 65 response = urllib2.urlopen(dynamic_server + filename) |
65 assert expected_output == response.read().strip() | 66 assert expected_output == response.read().strip() |
| 67 |
| 68 |
| 69 def test_cache(output_pages): |
| 70 source = FileSource(os.path.join('test_site')) |
| 71 assert source.get_cache_dir() == os.path.join('test_site', 'cache') |
LEFT | RIGHT |