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

Side by Side Diff: tests/test_dynamic_server.py

Issue 29912588: Issue 7019 - [CMS] Refactor `test_server.py` (Closed)
Patch Set: Addressed comments from Patch Set #3 Created Oct. 23, 2018, 4:42 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 import pytest
2 import urllib2
3 import os
4
5 from tests.test_page_outputs import dynamic_expected_outputs
6 from tests.utils import run_test_server, exception_test
7
8
9 @pytest.fixture(scope='function')
10 def dynamic_server_werkzeug(temp_site):
11 """Test server run using the `werkzeug` module."""
12 with run_test_server(str(temp_site)) as ts:
13 yield ts
14
15
16 @pytest.fixture(scope='function')
17 def dynamic_server_builtins(temp_site, tmpdir):
18 """Test server run using builtin modules."""
19 # Creating an invalid `werkzeug` module and add it to the head of the
Vasily Kuznetsov 2018/10/24 13:31:53 👍
20 # PYTHONPATH. This would cause the import of `werkzeug` to fail when
21 # running the test server and force it to use the builtin modules.
22 werkzeug_dir = tmpdir.mkdir('werkzeug')
23 werkzeug_dir.join('__init__.py').write('raise ImportError')
24 new_env = dict(os.environ)
25 new_env['PYTHONPATH'] = os.pathsep.join([str(tmpdir),
26 os.getenv('PYTHONPATH', '')])
27
28 with run_test_server(str(temp_site), new_env) as ts:
29 yield ts
30
31
32 @pytest.mark.slowtest
33 def test_dynamic_werkzeug_good_page(dynamic_server_werkzeug):
34 filename, expected_output = dynamic_expected_outputs[0]
35 response = urllib2.urlopen(dynamic_server_werkzeug + filename)
36
37 assert expected_output in response.read().strip()
38
39
40 @pytest.mark.slowtest
41 def test_dynamic_werkzeug_not_found(dynamic_server_werkzeug):
42 filename = 'en/no-page-here'
43 exp_msg = 'Not Found'
44
45 exception_test(urllib2.urlopen, urllib2.HTTPError, exp_msg,
46 dynamic_server_werkzeug + filename)
47
48
49 @pytest.mark.slowtest
50 def test_dynamic_builtins_good_page(dynamic_server_builtins):
51 filename, expected_output = dynamic_expected_outputs[0]
52 response = urllib2.urlopen(dynamic_server_builtins + filename)
53
54 assert expected_output in response.read().strip()
55
56
57 @pytest.mark.slowtest
58 def test_dynamic_builtins_not_found(dynamic_server_builtins):
59 filename = 'en/no-page-here'
60 exp_msg = 'Not Found'
61
62 exception_test(urllib2.urlopen, urllib2.HTTPError, exp_msg,
63 dynamic_server_builtins + filename)
OLDNEW
« cms/bin/test_server.py ('K') | « tests/conftest.py ('k') | tests/test_page_outputs.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld