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

Side by Side Diff: tests/test_xtm_translate.py

Issue 29908581: Issue #7036 - [XTM Integration] Add support for providing workflow name (Closed)
Patch Set: Created Oct. 12, 2018, 2:03 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
OLDNEW
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-present eyeo GmbH 2 # Copyright (C) 2006-present eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 from __future__ import unicode_literals 16 from __future__ import unicode_literals
17 17
18 import os 18 import os
19 from ConfigParser import SafeConfigParser 19 from ConfigParser import SafeConfigParser
20 import io 20 import io
21 import sys 21 import sys
22 import json 22 import json
23 23
24 import pytest 24 import pytest
25 25
26 from cms.translations.xtm import constants as const 26 from cms.translations.xtm import constants as const
27 from cms.translations.xtm.projects_handler import (
28 create_project, upload_files, download_files,
29 )
30 from cms.translations.xtm.cli import ( 27 from cms.translations.xtm.cli import (
31 generate_token, handle_projects as main_project_handler, 28 generate_token, handle_projects as main_project_handler,
32 ) 29 )
30 from tests.utils import XtmMockArgs
33 31
34 _CMD_START = ['python', '-m', 'cms.bin.xtm_translations'] 32 _CMD_START = ['python', '-m', 'cms.bin.xtm_translations']
35 33
36 _ENV_NO_TOKEN = dict(os.environ) 34 _ENV_NO_TOKEN = dict(os.environ)
37 _ENV_NO_TOKEN.pop(const.Token.ENV_VAR, None) 35 _ENV_NO_TOKEN.pop(const.Token.ENV_VAR, None)
38 36
39 _ENV_TOKEN_VALID = dict(os.environ) 37 _ENV_TOKEN_VALID = dict(os.environ)
40 _ENV_TOKEN_VALID[const.Token.ENV_VAR] = 'TheXTM-APIToken-VALID' 38 _ENV_TOKEN_VALID[const.Token.ENV_VAR] = 'TheXTM-APIToken-VALID'
41 39
42 _ENV_TOKEN_INVALID = dict(os.environ) 40 _ENV_TOKEN_INVALID = dict(os.environ)
43 _ENV_TOKEN_INVALID[const.Token.ENV_VAR] = 'TheXTM-APIToken-INVALID' 41 _ENV_TOKEN_INVALID[const.Token.ENV_VAR] = 'TheXTM-APIToken-INVALID'
44 42
45
46 class _CreationArgsNamespace:
47 def __init__(self):
48 pass
49
50 name = 'bar'
51 desc = 'foo'
52 client_id = 10
53 ref_id = 'faz'
54 workflow_id = 20
55 save_id = False
56 source_dir = None
57 projects_func = staticmethod(create_project)
58 source_lang = 'en_US'
59
60
61 class _UploadArgsNamespace:
62 def __init__(self):
63 pass
64
65 source_dir = None
66 projects_func = staticmethod(upload_files)
67 no_overwrite = False
68
69
70 class _DownloadArgsNamespace:
71 def __init__(self):
72 pass
73
74 source_dir = None
75 projects_func = staticmethod(download_files)
76
77
78 _CREATION_ARGS_DEFAULT = ['--name', 'bar', '--desc', 'foo', '--client-id', 43 _CREATION_ARGS_DEFAULT = ['--name', 'bar', '--desc', 'foo', '--client-id',
79 '10', '--ref-id', 'faz', '--workflow-id', '20'] 44 '10', '--ref-id', 'faz', '--workflow-id', '20']
80 _CREATION_ARGS_INVALID_TYPE_1 = ['--name', 'bar', '--desc', 'foo', 45 _CREATION_ARGS_INVALID_TYPE_1 = ['--name', 'bar', '--desc', 'foo',
81 '--client-id', 'foo', '--ref-id', 'faz', 46 '--client-id', 'foo', '--ref-id', 'faz',
82 '--workflow-id', '3'] 47 '--workflow-id', '3']
83 _CREATION_ARGS_INVALID_TYPE_2 = ['--name', 'bar', '--desc', 'foo', 48 _CREATION_ARGS_INVALID_TYPE_2 = ['--name', 'bar', '--desc', 'foo',
84 '--client-id', '23', '--ref-id', 'faz', 49 '--client-id', '23', '--ref-id', 'faz',
85 '--workflow-id', 'foo'] 50 '--workflow-id', 'foo']
86 51
52 _UploadArgsNamespace = XtmMockArgs.UploadArgsNamespace
53 _CreationArgsNamespace = XtmMockArgs.CreationArgsNamespace
54 _DownloadArgsNamespace = XtmMockArgs.DownloadArgsNamespace
55
87 56
88 @pytest.fixture 57 @pytest.fixture
89 def env_valid_token(): 58 def env_valid_token():
90 old_env = os.environ 59 old_env = os.environ
91 os.environ = _ENV_TOKEN_VALID 60 os.environ = _ENV_TOKEN_VALID
92 yield True 61 yield True
93 os.environ = old_env 62 os.environ = old_env
94 63
95 64
96 @pytest.mark.script_launch_mode('subprocess') 65 @pytest.mark.script_launch_mode('subprocess')
97 @pytest.mark.parametrize('args,exp_msg', [ 66 @pytest.mark.parametrize('args,exp_msg', [
98 (['-h'], 'usage: xtm_translations.py [-h] [-v] ' 67 (['-h'], 'usage: xtm_translations.py [-h] [-v] '
99 '{login,create,upload,download} ...'), 68 '{login,create,upload,download} ...'),
100 (['create', '-h'], 'usage: xtm_translations.py create [-h] --name NAME ' 69 (['create', '-h'], 'usage: xtm_translations.py create [-h] --name NAME '
101 '--desc DESC --client-id CLIENT_ID --ref-id REF_ID ' 70 '--desc DESC --client-id CLIENT_ID --ref-id REF_ID '
102 '--workflow-id WORKFLOW_ID [--source-lang SOURCE_LANG] ' 71 '--workflow-id WORKFLOW_ID [--source-lang '
103 '[--save-id] [source_dir]'), 72 'SOURCE_LANG] [--save-id] [--workflow-name '
73 'WORKFLOW_NAME] [source_dir]'),
104 (['upload', '-h'], 'usage: xtm_translations.py upload [-h] ' 74 (['upload', '-h'], 'usage: xtm_translations.py upload [-h] '
105 '[--no-overwrite] [source_dir]'), 75 '[--no-overwrite] [source_dir]'),
106 (['download', '-h'], 'usage: xtm_translations.py download [-h] ' 76 (['download', '-h'], 'usage: xtm_translations.py download [-h] '
107 '[source_dir]'), 77 '[source_dir]'),
108 ]) 78 ])
109 def test_usage_messages(args, exp_msg, script_runner): 79 def test_usage_messages(args, exp_msg, script_runner):
110 """Test if appropriate usage messages are displayed.""" 80 """Test if appropriate usage messages are displayed."""
111 cmd = list(_CMD_START) 81 cmd = list(_CMD_START)
112 cmd.extend(args) 82 cmd.extend(args)
113 ret = script_runner.run(*cmd) 83 ret = script_runner.run(*cmd)
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
304 274
305 main_project_handler(namespace) 275 main_project_handler(namespace)
306 276
307 with open(os.path.join(temp_site_valid_project, 'locales', 'de', 277 with open(os.path.join(temp_site_valid_project, 'locales', 'de',
308 'file.json')) as f: 278 'file.json')) as f:
309 assert json.dumps({'foo': 'bar', 'faz': 'baz'}) == f.read() 279 assert json.dumps({'foo': 'bar', 'faz': 'baz'}) == f.read()
310 280
311 with open(os.path.join(temp_site_valid_project, 'locales', 'de', 'foo', 281 with open(os.path.join(temp_site_valid_project, 'locales', 'de', 'foo',
312 'file-utf8.json'), 'rb') as f: 282 'file-utf8.json'), 'rb') as f:
313 assert json.loads(f.read()) == {'foo': '\u1234'} 283 assert json.loads(f.read()) == {'foo': '\u1234'}
OLDNEW

Powered by Google App Engine
This is Rietveld