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: Created Feb. 9, 2018, 11:03 p.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 CrowdinConfig, mockapi 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'),
22 ('delete-file?key=test_key&json=1', '.json'),
23 ('delete-file?key=test_key&json=1', '.json'),
24 ('delete-directory?key=test_key&json=1', ''),
23 ('delete-directory?key=test_key&json=1', ''), 25 ('delete-directory?key=test_key&json=1', ''),
24 ('export?key=test_key&json=1', ''), 26 ('export?key=test_key&json=1', ''),
25 ('download/all.zip?key=test_key', ''), 27 ('download/all.zip?key=test_key', ''),
26 ] 28 ]
27 29
28 30
29 @pytest.fixture(scope='module') 31 @pytest.fixture
30 def api_zip(temp_site, request): 32 def api_zip(tmpdir, temp_site, request):
31 zip_name = 'all'
32 input_dir = os.path.join(temp_site, 'locales') 33 input_dir = os.path.join(temp_site, 'locales')
33 shutil.make_archive(zip_name, 'zip', input_dir) 34 shutil.make_archive(tmpdir.join('all').strpath, 'zip', input_dir)
34 yield zipfile.ZipFile(zip_name + '.zip') 35 return tmpdir.strpath
35 os.remove(zip_name + '.zip')
36 36
37 37
38 @pytest.fixture(scope='session') 38 @pytest.fixture
39 def mock_api(temp_site): 39 def mock_api(temp_site, api_zip):
Jon Sonesen 2018/02/09 23:08:01 I know this is purely cosmetic but it sort of make
40 config = CrowdinConfig(os.path.join(temp_site, 'locales')) 40 app = crowdin_mock_api.load(os.path.join(temp_site, 'locales'), api_zip)
41 host = 'api.crowdin.com' 41 host = 'api.crowdin.com'
42 port = 443 42 port = 443
43 app = mockapi(config)
44 urllib3_intercept.install() 43 urllib3_intercept.install()
45 add_wsgi_intercept(host, port, lambda: app.wsgi_app) 44 add_wsgi_intercept(host, port, lambda: app.wsgi_app)
46 yield app 45 yield app
47 remove_wsgi_intercept() 46 remove_wsgi_intercept()
48 47
49 48
50 def test_sync(temp_site, mock_api, api_zip, expect_requests): 49 def test_sync(temp_site, mock_api, expect_requests):
51 translate.crowdin_sync(temp_site, 'test_key') 50 translate.crowdin_sync(temp_site, 'test_key')
52 for (url, data), (expect_url, expect_data) in zip(mock_api.request_log, 51 for (url, data), (expect_url, expect_data) in zip(mock_api.request_log,
53 expect_requests): 52 expect_requests):
54 assert expect_url in url 53 assert expect_url in url
55 assert expect_data in data 54 assert expect_data in data
LEFTRIGHT

Powered by Google App Engine
This is Rietveld