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

Unified Diff: tests/xtm_conftest.py

Issue 29886648: Issue #6942 - Add XTM integration in CMS (Closed)
Patch Set: Addressed comments from Patch Set #4 Created Oct. 5, 2018, 4:23 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: tests/xtm_conftest.py
diff --git a/tests/xtm_conftest.py b/tests/xtm_conftest.py
new file mode 100644
index 0000000000000000000000000000000000000000..68e62e344f2b98d096bd8923c91a20c6e3d6b2e3
--- /dev/null
+++ b/tests/xtm_conftest.py
@@ -0,0 +1,114 @@
+from __future__ import unicode_literals
+
+import os
+import shutil
+import json
+
+import pytest
+from cms.sources import FileSource
+from wsgi_intercept import add_wsgi_intercept
+from wsgi_intercept import remove_wsgi_intercept
+from wsgi_intercept import requests_intercept
+
+from tests.xtm_mock_api import get_configured_app
+
+_INTERCEPT_PORT = 443
+_INTERCEPT_HOST = 'wstest2.xtm-intl.com'
+
+ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
+
+
+@pytest.fixture
+def temp_site_invalid_locales(tmpdir):
+ out_dir = tmpdir.mkdir('temp_out_invalid_locales')
+ site_dir = out_dir.join('test_site').strpath
+
+ shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
+ invalid_locale = site_dir.join('locales').mkdir('foo')
+ invalid_locale.join('test.json').write(json.dumps({'a': 'b'}))
+ return site_dir
+
+
+@pytest.fixture
+def temp_site_invalid_project(tmpdir):
+ out_dir = tmpdir.mkdir('temp_out_invalid')
+ site_dir = out_dir.join('test_site').strpath
+
+ shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
+ with FileSource(str(site_dir)) as fs:
+ fs.write_to_config('XTM', 'project_id', '1111')
+
+ return site_dir
+
+
+@pytest.fixture
+def temp_site_valid_project(tmpdir):
+ out_dir = tmpdir.mkdir('temp_out_valid')
+ site_dir = out_dir.join('test_site').strpath
+
+ shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
+ with FileSource(str(site_dir)) as fs:
+ fs.write_to_config('XTM', 'project_id', '1234')
+
+ return site_dir
+
+
+@pytest.fixture
+def temp_site_no_target_files(tmpdir):
+ out_dir = tmpdir.mkdir('temp_out_no_targets')
+ site_dir = out_dir.join('test_site').strpath
+
+ shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
+ with FileSource(str(site_dir)) as fs:
+ fs.write_to_config('XTM', 'project_id', '9999')
+
+ return site_dir
+
+
+@pytest.fixture
+def temp_site_function_scope(tmpdir):
+ out_dir = tmpdir.mkdir('temp_site_func')
+ site_dir = out_dir.join('test_site').strpath
+
+ shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir)
+
+ return site_dir
+
+
+@pytest.fixture
+def intercept():
+ app = get_configured_app()
+ requests_intercept.install()
+ add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app)
+ yield app
+ remove_wsgi_intercept()
+
+
+@pytest.fixture
+def intercept_populated():
+ files = [
+ {
+ 'name': 'file.json',
+ 'data': json.dumps({'foo': 'bar', 'faz': 'baz'}),
+ },
+ {
+ 'name': '___foo___file-utf8.json',
+ 'data': json.dumps({'foo': '\u1234'}),
+ },
+ ]
+ targets = ['de_DE']
+ app = get_configured_app(files=files, target_langs=targets)
+ requests_intercept.install()
+ add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app)
+ yield app
+ remove_wsgi_intercept()
+
+
+@pytest.fixture
+def intercept_too_many_targets():
+ targets = ['de_DE', 'es_ES']
+ app = get_configured_app(target_langs=targets)
+ requests_intercept.install()
+ add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app)
+ yield app
+ remove_wsgi_intercept()
« docs/usage/xml-sync.md ('K') | « tests/utils.py ('k') | tests/xtm_mock_api.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld