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

Delta Between Two Patch Sets: tests/conftest.py

Issue 29886648: Issue #6942 - Add XTM integration in CMS (Closed)
Left Patch Set: Created Sept. 20, 2018, 4:24 p.m.
Right Patch Set: Addressed comments from Patch Set #4 Created Oct. 5, 2018, 4:23 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 from __future__ import unicode_literals 1 from __future__ import unicode_literals
2 2
3 import os 3 import os
4 import pytest 4 import pytest
5 import shutil 5 import shutil
6 import json
7 6
8 from wsgi_intercept import add_wsgi_intercept 7 pytest_plugins = [
9 from wsgi_intercept import remove_wsgi_intercept 8 'tests.xtm_conftest',
10 from wsgi_intercept import requests_intercept 9 ]
11
12 from tests.xtm_mock_api import get_configured_app
13 from cms.sources import FileSource
14 10
15 _INTERCEPT_PORT = 443 11 _INTERCEPT_PORT = 443
16 _INTERCEPT_HOST = 'wstest2.xtm-intl.com' 12 _INTERCEPT_HOST = 'wstest2.xtm-intl.com'
17 13
18 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 14 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
19 15
20 16
21 @pytest.fixture(scope='session') 17 @pytest.fixture(scope='session')
22 def temp_site(tmpdir_factory): 18 def temp_site(tmpdir_factory):
23 out_dir = tmpdir_factory.mktemp('temp_out') 19 out_dir = tmpdir_factory.mktemp('temp_out')
24 site_dir = out_dir.join('test_site').strpath 20 site_dir = out_dir.join('test_site').strpath
25 21
26 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) 22 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
27 yield site_dir 23 yield site_dir
28
29
30 @pytest.fixture(scope='session')
31 def temp_site_invalid_locales(tmpdir_factory):
32 out_dir = tmpdir_factory.mktemp('temp_out_invalid_locales')
33 site_dir = out_dir.join('test_site').strpath
34
35 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
36 invalid_locale = site_dir.join('locales').mktemp('foo')
37 invalid_locale.join('test.json').write(json.dumps({'a': 'b'}))
38 yield site_dir
39
40
41 @pytest.fixture(scope='session')
42 def temp_site_invalid_project(tmpdir_factory):
43 out_dir = tmpdir_factory.mktemp('temp_out_invalid')
44 site_dir = out_dir.join('test_site').strpath
45
46 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
47 with FileSource(str(site_dir)) as fs:
48 fs.write_to_config('XTM', 'project_id', '1111')
49
50 yield site_dir
51
52
53 @pytest.fixture(scope='session')
54 def temp_site_valid_project(tmpdir_factory):
55 out_dir = tmpdir_factory.mktemp('temp_out_valid')
56 site_dir = out_dir.join('test_site').strpath
57
58 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
59 with FileSource(str(site_dir)) as fs:
60 fs.write_to_config('XTM', 'project_id', '1234')
61
62 yield site_dir
63
64
65 @pytest.fixture(scope='session')
66 def temp_site_no_target_files(tmpdir_factory):
67 out_dir = tmpdir_factory.mktemp('temp_out_no_targets')
68 site_dir = out_dir.join('test_site').strpath
69
70 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
71 with FileSource(str(site_dir)) as fs:
72 fs.write_to_config('XTM', 'project_id', '9999')
73
74 yield site_dir
75
76
77 @pytest.fixture
78 def intercept():
79 app = get_configured_app()
80 requests_intercept.install()
81 add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app)
82 yield app
83 remove_wsgi_intercept()
84
85
86 @pytest.fixture
87 def intercept_populated():
88 files = [
89 {
90 'name': 'file.json',
91 'data': json.dumps({'foo': 'bar', 'faz': 'baz'}),
92 },
93 {
94 'name': '___foo___file-utf8.json',
95 'data': json.dumps({'foo': '\u1234'}),
96 },
97 ]
98 targets = ['de_DE']
99 app = get_configured_app(files=files, target_langs=targets)
100 requests_intercept.install()
101 add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app)
102 yield app
103 remove_wsgi_intercept()
104
105
106 @pytest.fixture
107 def intercept_too_many_targets():
108 targets = ['de_DE', 'es_ES']
109 app = get_configured_app(target_langs=targets)
110 requests_intercept.install()
111 add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app)
112 yield app
113 remove_wsgi_intercept()
LEFTRIGHT

Powered by Google App Engine
This is Rietveld