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

Delta Between Two Patch Sets: tests/test_translations.py

Issue 29693633: Noissue - Add crowdin api config support (Closed) Base URL: https://hg.adblockplus.org/cms
Left Patch Set: fix indentation error causing improper config load Created Feb. 17, 2018, 10:37 a.m.
Right Patch Set: Actually address PS6 comments Created March 12, 2018, 9:14 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
« no previous file with change/comment | « tests/crowdin_mock_api.py ('k') | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 import os 1 import os
2 import shutil 2 import shutil
3 import pytest 3 import pytest
4 import zipfile
5 4
6 from wsgi_intercept import urllib3_intercept 5 from wsgi_intercept import urllib3_intercept
7 from wsgi_intercept import add_wsgi_intercept 6 from wsgi_intercept import add_wsgi_intercept
8 from wsgi_intercept import remove_wsgi_intercept 7 from wsgi_intercept import remove_wsgi_intercept
9 8
10 from crowdin_mock_api import CrowdinMock 9 import crowdin_mock_api
11 from cms.bin import translate 10 from cms.bin import translate
12 11
13 12
14 @pytest.fixture(scope='module') 13 @pytest.fixture(scope='module')
15 def expect_requests(): 14 def expect_requests():
16 return [ 15 return [
17 ('info?key=test_key&json=1', ''), 16 ('info?key=test_key&json=1', ''),
18 ('supported-languages?key=test_key&json=1', ''), 17 ('supported-languages?key=test_key&json=1', ''),
19 ('add-file?key=test_key&json=1', '.json'), 18 ('add-file?key=test_key&json=1', '.json'),
20 ('upload-translation?key=test_key&json=1', 'simple'), 19 ('upload-translation?key=test_key&json=1', 'simple'),
21 ('delete-file?key=test_key&json=1', '.json'), 20 ('delete-file?key=test_key&json=1', '.json'),
22 ('delete-file?key=test_key&json=1', '.json'), 21 ('delete-file?key=test_key&json=1', '.json'),
23 ('delete-file?key=test_key&json=1', '.json'), 22 ('delete-file?key=test_key&json=1', '.json'),
24 ('delete-file?key=test_key&json=1', '.json'), 23 ('delete-file?key=test_key&json=1', '.json'),
25 ('delete-directory?key=test_key&json=1', ''), 24 ('delete-directory?key=test_key&json=1', ''),
26 ('delete-directory?key=test_key&json=1', ''), 25 ('delete-directory?key=test_key&json=1', ''),
27 ('export?key=test_key&json=1', ''), 26 ('export?key=test_key&json=1', ''),
28 ('download/all.zip?key=test_key', ''), 27 ('download/all.zip?key=test_key', ''),
29 ] 28 ]
30 29
31 30
32 @pytest.fixture(scope='module') 31 @pytest.fixture
33 def api_zip(temp_site, request): 32 def api_zip(tmpdir, temp_site, request):
34 zip_name = 'all'
35 input_dir = os.path.join(temp_site, 'locales') 33 input_dir = os.path.join(temp_site, 'locales')
36 shutil.make_archive(zip_name, 'zip', input_dir) 34 shutil.make_archive(tmpdir.join('all').strpath, 'zip', input_dir)
37 yield zipfile.ZipFile(zip_name + '.zip') 35 return tmpdir.strpath
38 os.remove(zip_name + '.zip')
39 36
40 37
41 @pytest.fixture(scope='session') 38 @pytest.fixture
42 def mock_api(temp_site): 39 def mock_api(temp_site, api_zip):
43 api = CrowdinMock(os.path.join(temp_site, 'locales')) 40 app = crowdin_mock_api.load(os.path.join(temp_site, 'locales'), api_zip)
44 api.run()
45 host = 'api.crowdin.com' 41 host = 'api.crowdin.com'
46 port = 443 42 port = 443
47 urllib3_intercept.install() 43 urllib3_intercept.install()
48 add_wsgi_intercept(host, port, lambda: api.app.wsgi_app) 44 add_wsgi_intercept(host, port, lambda: app.wsgi_app)
49 yield api 45 yield app
50 remove_wsgi_intercept() 46 remove_wsgi_intercept()
51 47
52 48
53 def test_sync(temp_site, mock_api, api_zip, expect_requests): 49 def test_sync(temp_site, mock_api, expect_requests):
54 translate.crowdin_sync(temp_site, 'test_key') 50 translate.crowdin_sync(temp_site, 'test_key')
55 for (url, data), (expect_url, expect_data) in zip(mock_api.app.request_log, 51 for (url, data), (expect_url, expect_data) in zip(mock_api.request_log,
56 expect_requests): 52 expect_requests):
57 assert expect_url in url 53 assert expect_url in url
58 assert expect_data in data 54 assert expect_data in data
LEFTRIGHT

Powered by Google App Engine
This is Rietveld