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

Side by Side Diff: tests/test_translations.py

Issue 29693633: Noissue - Add crowdin api config support (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: address PS4 comments Created March 6, 2018, 2:28 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« tests/crowdin_mock_api.py ('K') | « tests/crowdin_mock_api.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 import os 1 import os
2 import shutil 2 import shutil
3 import pytest 3 import pytest
4
4 from wsgi_intercept import urllib3_intercept 5 from wsgi_intercept import urllib3_intercept
5 from wsgi_intercept import add_wsgi_intercept 6 from wsgi_intercept import add_wsgi_intercept
6 from wsgi_intercept import remove_wsgi_intercept 7 from wsgi_intercept import remove_wsgi_intercept
7 8
8 from crowdin_mock_api import app 9 import crowdin_mock_api
9 from cms.bin import translate 10 from cms.bin import translate
10 11
11 12
12 @pytest.fixture(scope='module') 13 @pytest.fixture(scope='module')
13 def expect_requests(): 14 def expect_requests():
14 return [ 15 return [
15 ('info?key=test_key&json=1', ''), 16 ('info?key=test_key&json=1', ''),
16 ('supported-languages?key=test_key&json=1', ''), 17 ('supported-languages?key=test_key&json=1', ''),
17 ('add-file?key=test_key&json=1', 'translate.json'), 18 ('add-file?key=test_key&json=1', '.json'),
18 ('upload-translation?key=test_key&json=1', 'simple'), 19 ('upload-translation?key=test_key&json=1', 'simple'),
19 ('delete-file?key=test_key&json=1', 'translate.json'), 20 ('delete-file?key=test_key&json=1', '.json'),
20 ('delete-file?key=test_key&json=1', 'translate.json'), 21 ('delete-file?key=test_key&json=1', '.json'),
22 ('delete-file?key=test_key&json=1', '.json'),
23 ('delete-file?key=test_key&json=1', '.json'),
21 ('delete-directory?key=test_key&json=1', ''), 24 ('delete-directory?key=test_key&json=1', ''),
22 ('delete-directory?key=test_key&json=1', ''), 25 ('delete-directory?key=test_key&json=1', ''),
23 ('export?key=test_key&json=1', ''), 26 ('export?key=test_key&json=1', ''),
24 ('download/all.zip?key=test_key', ''), 27 ('download/all.zip?key=test_key', ''),
25 ] 28 ]
26 29
27 30
28 @pytest.fixture(scope='module') 31 @pytest.fixture
29 def make_crowdin_zip(temp_site): 32 def api_zip(tmpdir, temp_site, request):
30 zip_name = os.path.join('tests', 'all')
31 input_dir = os.path.join(temp_site, 'locales') 33 input_dir = os.path.join(temp_site, 'locales')
32 shutil.make_archive(zip_name, 'zip', input_dir) 34 shutil.make_archive(tmpdir.join('all').strpath, 'zip', input_dir)
33 yield None 35 return tmpdir.strpath
34 os.remove(zip_name + '.zip')
35 36
36 37
37 @pytest.fixture() 38 @pytest.fixture
38 def make_intercept(scope='module'): 39 def mock_api(temp_site, api_zip):
40 app = crowdin_mock_api.load(os.path.join(temp_site, 'locales'), api_zip)
39 host = 'api.crowdin.com' 41 host = 'api.crowdin.com'
40 port = 443 42 port = 443
41 urllib3_intercept.install() 43 urllib3_intercept.install()
42 add_wsgi_intercept(host, port, lambda: app.wsgi_app) 44 add_wsgi_intercept(host, port, lambda: app.wsgi_app)
43 yield None 45 yield app
44 remove_wsgi_intercept() 46 remove_wsgi_intercept()
45 47
46 48
47 def test_sync(temp_site, make_intercept, make_crowdin_zip, expect_requests): 49 def test_sync(temp_site, mock_api, expect_requests):
48 translate.crowdin_sync(temp_site, 'test_key') 50 translate.crowdin_sync(temp_site, 'test_key')
49 for (url, data), (expect_url, expect_data) in zip(app.request_log, 51 for (url, data), (expect_url, expect_data) in zip(mock_api.request_log,
50 expect_requests): 52 expect_requests):
51 assert expect_url in url 53 assert expect_url in url
52 assert expect_data in data 54 assert expect_data in data
OLDNEW
« tests/crowdin_mock_api.py ('K') | « tests/crowdin_mock_api.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld