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

Side by Side Diff: tests/conftest.py

Issue 29886648: Issue #6942 - Add XTM integration in CMS (Closed)
Patch Set: Created Sept. 20, 2018, 4:24 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
1 from __future__ import unicode_literals
2
1 import os 3 import os
2 import pytest 4 import pytest
3 import shutil 5 import shutil
6 import json
4 7
8 from wsgi_intercept import add_wsgi_intercept
9 from wsgi_intercept import remove_wsgi_intercept
10 from wsgi_intercept import requests_intercept
11
12 from tests.xtm_mock_api import get_configured_app
13 from cms.sources import FileSource
14
15 _INTERCEPT_PORT = 443
16 _INTERCEPT_HOST = 'wstest2.xtm-intl.com'
5 17
6 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 18 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7 19
8 20
9 @pytest.fixture(scope='session') 21 @pytest.fixture(scope='session')
10 def temp_site(tmpdir_factory): 22 def temp_site(tmpdir_factory):
11 out_dir = tmpdir_factory.mktemp('temp_out') 23 out_dir = tmpdir_factory.mktemp('temp_out')
12 site_dir = out_dir.join('test_site').strpath 24 site_dir = out_dir.join('test_site').strpath
13 25
14 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) 26 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
15 yield site_dir 27 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()
OLDNEW

Powered by Google App Engine
This is Rietveld