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

Side by Side Diff: tests/test_translations.py

Issue 29647615: Noissue - Refactor translation tests to validate sync (Closed)
Patch Set: Created Dec. 22, 2017, 3:43 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « 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 sys
3 import runpy
2 import shutil 4 import shutil
3 import pytest 5 import pytest
6 import zipfile
4 from wsgi_intercept import urllib3_intercept 7 from wsgi_intercept import urllib3_intercept
5 from wsgi_intercept import add_wsgi_intercept 8 from wsgi_intercept import add_wsgi_intercept
6 from wsgi_intercept import remove_wsgi_intercept 9 from wsgi_intercept import remove_wsgi_intercept
7 10
8 from crowdin_mock_api import app 11 from crowdin_mock_api import app
9 from cms.bin import translate
10 12
11 13
12 @pytest.fixture(scope='module') 14 @pytest.fixture(scope='module')
13 def expect_requests(): 15 def api_zip(temp_site, request):
Vasily Kuznetsov 2018/01/02 15:10:04 Am I right that the purpose of this fixture is to
Jon Sonesen 2018/01/05 10:27:07 No, this generated the zips that the test validate
Vasily Kuznetsov 2018/01/05 14:30:16 Ok, I see. But then I'm not sure what this test is
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', ''),
22 ('delete-directory?key=test_key&json=1', ''),
23 ('export?key=test_key&json=1', ''),
24 ('download/all.zip?key=test_key', ''),
25 ]
26
27
28 @pytest.fixture(scope='module')
29 def make_crowdin_zip(temp_site):
30 zip_name = os.path.join('tests', 'all') 16 zip_name = os.path.join('tests', 'all')
31 input_dir = os.path.join(temp_site, 'locales') 17 input_dir = os.path.join(temp_site, 'locales')
32 shutil.make_archive(zip_name, 'zip', input_dir) 18 shutil.make_archive(zip_name, 'zip', input_dir)
33 yield None 19 yield zipfile.ZipFile(zip_name + '.zip')
34 os.remove(zip_name + '.zip') 20 os.remove(zip_name + '.zip')
21 return
35 22
36 23
37 @pytest.fixture() 24 @pytest.fixture()
38 def make_intercept(scope='module'): 25 def make_intercept(scope='module'):
39 host = 'api.crowdin.com' 26 host = 'api.crowdin.com'
40 port = 443 27 port = 443
41 urllib3_intercept.install() 28 urllib3_intercept.install()
42 add_wsgi_intercept(host, port, lambda: app.wsgi_app) 29 add_wsgi_intercept(host, port, lambda: app.wsgi_app)
43 yield None 30 yield None
44 remove_wsgi_intercept() 31 remove_wsgi_intercept()
45 32
46 33
47 def test_sync(temp_site, make_intercept, make_crowdin_zip, expect_requests): 34 def test_sync(temp_site, make_intercept, api_zip):
48 translate.crowdin_sync(temp_site, 'test_key') 35 sys.argv = [None, temp_site, 'test_key']
49 for (url, data), (expect_url, expect_data) in zip(app.request_log, 36 runpy.run_module('cms.bin.translate', run_name='__main__')
50 expect_requests): 37 for locale in [os.path.dirname(x) for x in api_zip.namelist()]:
51 assert expect_url in url 38 assert locale in os.listdir(os.path.join(temp_site, 'locales'))
Vasily Kuznetsov 2018/01/02 15:10:04 I get an error here: def test_sync(temp_site,
Jon Sonesen 2018/01/05 10:27:07 odd, i dont, but will look into it
Vasily Kuznetsov 2018/01/05 14:30:16 I printed `api_zip.namelist()` in this test and it
52 assert expect_data in data
OLDNEW
« no previous file with comments | « tests/crowdin_mock_api.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld