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

Delta Between Two Patch Sets: tests/test_translations.py

Issue 29355396: Issue 4380 - Add Mock Crowdin API and Sync Test (Closed)
Left Patch Set: Created Sept. 30, 2016, 7:20 a.m.
Right Patch Set: formatting fix Created Oct. 25, 2016, 8:15 a.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/test_site/settings.ini ('k') | tox.ini » ('j') | 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 mock_api
5 from wsgi_intercept import urllib3_intercept 4 from wsgi_intercept import urllib3_intercept
6 from wsgi_intercept import add_wsgi_intercept 5 from wsgi_intercept import add_wsgi_intercept
7 from wsgi_intercept import remove_wsgi_intercept 6 from wsgi_intercept import remove_wsgi_intercept
8 7
8 from crowdin_mock_api import app
9 from cms.bin import translate 9 from cms.bin import translate
10
11
12 @pytest.fixture(scope='module')
13 def expect_requests():
14 return [
15 ('info?key=test_key&json=1', ''),
16 ('supported-languages?key=test_key&json=1', ''),
17 ('add-file?key=test_key&json=1', 'translate.json'),
18 ('upload-translation?key=test_key&json=1', 'test_sample'),
19 ('delete-file?key=test_key&json=1', 'translate.json'),
20 ('delete-file?key=test_key&json=1', 'translate.json'),
21 ('delete-directory?key=test_key&json=1', 'de'),
22 ('delete-directory?key=test_key&json=1', 'en'),
23 ('export?key=test_key&json=1', ''),
24 ('download/all.zip?key=test_key', ''),
25 ]
10 26
11 27
12 @pytest.fixture(scope='module') 28 @pytest.fixture(scope='module')
13 def make_crowdin_zip(temp_site): 29 def make_crowdin_zip(temp_site):
14 zip_name = os.path.join('tests', 'all') 30 zip_name = os.path.join('tests', 'all')
15 input_dir = os.path.join(temp_site, 'locales') 31 input_dir = os.path.join(temp_site, 'locales')
16 shutil.make_archive(zip_name, 'zip', input_dir) 32 shutil.make_archive(zip_name, 'zip', input_dir)
Jon Sonesen 2016/09/30 07:33:56 the archive is not made in the temp site because t
17 yield None 33 yield None
18 os.remove(zip_name + '.zip') 34 os.remove(zip_name + '.zip')
19 35
20 36
21 @pytest.fixture() 37 @pytest.fixture()
22 def make_intercept(scope='module'): 38 def make_intercept(scope='module'):
23 host = 'api.crowdin.com' 39 host = 'api.crowdin.com'
24 port = 443 40 port = 443
25 urllib3_intercept.install() 41 urllib3_intercept.install()
26 add_wsgi_intercept(host, port, lambda: mock_api.app.wsgi_app) 42 add_wsgi_intercept(host, port, lambda: app.wsgi_app)
27 yield None 43 yield None
28 remove_wsgi_intercept() 44 remove_wsgi_intercept()
29 45
30 46
31 def test_sync(temp_site, make_intercept, make_crowdin_zip): 47 def test_sync(temp_site, make_intercept, make_crowdin_zip, expect_requests):
32 translate.crowdin_sync(temp_site, 'test_key') 48 translate.crowdin_sync(temp_site, 'test_key')
Vasily Kuznetsov 2016/09/30 14:38:31 As we discussed, we should add assertions to this
49 for (url, data), (expect_url, expect_data) in zip(
50 app.request_log,
51 expect_requests):
52 assert expect_url in url
53 assert expect_data in data
LEFTRIGHT

Powered by Google App Engine
This is Rietveld