OLD | NEW |
(Empty) | |
| 1 from __future__ import unicode_literals |
| 2 |
| 3 import os |
| 4 import shutil |
| 5 import json |
| 6 |
| 7 import pytest |
| 8 from cms.sources import FileSource |
| 9 from wsgi_intercept import add_wsgi_intercept |
| 10 from wsgi_intercept import remove_wsgi_intercept |
| 11 from wsgi_intercept import requests_intercept |
| 12 |
| 13 from tests.xtm_mock_api import get_configured_app |
| 14 |
| 15 _INTERCEPT_PORT = 443 |
| 16 _INTERCEPT_HOST = 'wstest2.xtm-intl.com' |
| 17 |
| 18 ROOTPATH = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) |
| 19 |
| 20 |
| 21 @pytest.fixture |
| 22 def temp_site_invalid_locales(tmpdir): |
| 23 out_dir = tmpdir.mkdir('temp_out_invalid_locales') |
| 24 site_dir = out_dir.join('test_site').strpath |
| 25 |
| 26 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) |
| 27 invalid_locale = site_dir.join('locales').mkdir('foo') |
| 28 invalid_locale.join('test.json').write(json.dumps({'a': 'b'})) |
| 29 return site_dir |
| 30 |
| 31 |
| 32 @pytest.fixture |
| 33 def temp_site_invalid_project(tmpdir): |
| 34 out_dir = tmpdir.mkdir('temp_out_invalid') |
| 35 site_dir = out_dir.join('test_site').strpath |
| 36 |
| 37 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) |
| 38 with FileSource(str(site_dir)) as fs: |
| 39 fs.write_to_config('XTM', 'project_id', '1111') |
| 40 |
| 41 return site_dir |
| 42 |
| 43 |
| 44 @pytest.fixture |
| 45 def temp_site_valid_project(tmpdir): |
| 46 out_dir = tmpdir.mkdir('temp_out_valid') |
| 47 site_dir = out_dir.join('test_site').strpath |
| 48 |
| 49 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) |
| 50 with FileSource(str(site_dir)) as fs: |
| 51 fs.write_to_config('XTM', 'project_id', '1234') |
| 52 |
| 53 return site_dir |
| 54 |
| 55 |
| 56 @pytest.fixture |
| 57 def temp_site_no_target_files(tmpdir): |
| 58 out_dir = tmpdir.mkdir('temp_out_no_targets') |
| 59 site_dir = out_dir.join('test_site').strpath |
| 60 |
| 61 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) |
| 62 with FileSource(str(site_dir)) as fs: |
| 63 fs.write_to_config('XTM', 'project_id', '9999') |
| 64 |
| 65 return site_dir |
| 66 |
| 67 |
| 68 @pytest.fixture |
| 69 def temp_site_function_scope(tmpdir): |
| 70 out_dir = tmpdir.mkdir('temp_site_func') |
| 71 site_dir = out_dir.join('test_site').strpath |
| 72 |
| 73 shutil.copytree(os.path.join(ROOTPATH, 'tests', 'test_site'), site_dir) |
| 74 |
| 75 return site_dir |
| 76 |
| 77 |
| 78 @pytest.fixture |
| 79 def intercept(): |
| 80 app = get_configured_app() |
| 81 requests_intercept.install() |
| 82 add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app) |
| 83 yield app |
| 84 remove_wsgi_intercept() |
| 85 |
| 86 |
| 87 @pytest.fixture |
| 88 def intercept_populated(): |
| 89 files = [ |
| 90 { |
| 91 'name': 'file.json', |
| 92 'data': json.dumps({'foo': 'bar', 'faz': 'baz'}), |
| 93 }, |
| 94 { |
| 95 'name': '___foo___file-utf8.json', |
| 96 'data': json.dumps({'foo': '\u1234'}), |
| 97 }, |
| 98 ] |
| 99 targets = ['de_DE'] |
| 100 app = get_configured_app(files=files, target_langs=targets) |
| 101 requests_intercept.install() |
| 102 add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app) |
| 103 yield app |
| 104 remove_wsgi_intercept() |
| 105 |
| 106 |
| 107 @pytest.fixture |
| 108 def intercept_too_many_targets(): |
| 109 targets = ['de_DE', 'es_ES'] |
| 110 app = get_configured_app(target_langs=targets) |
| 111 requests_intercept.install() |
| 112 add_wsgi_intercept(_INTERCEPT_HOST, _INTERCEPT_PORT, lambda: app) |
| 113 yield app |
| 114 remove_wsgi_intercept() |
OLD | NEW |