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

Side by Side Diff: tests/xtm_mock_api.py

Issue 29908581: Issue #7036 - [XTM Integration] Add support for providing workflow name (Closed)
Patch Set: Addressed comments from Patch Set 1 Created Oct. 18, 2018, 4:23 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
« tests/utils.py ('K') | « tests/utils.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 # 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
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 r'translationFiles\[(?P<idx>\d+)\].name'} 45 r'translationFiles\[(?P<idx>\d+)\].name'}
46 46
47 xtm_mock = Flask('mocking-XTM') 47 xtm_mock = Flask('mocking-XTM')
48 48
49 49
50 def get_configured_app(**kwargs): 50 def get_configured_app(**kwargs):
51 xtm_mock.config['rootdir'] = kwargs.pop('rootdir', '') 51 xtm_mock.config['rootdir'] = kwargs.pop('rootdir', '')
52 xtm_mock.config['target_languages'] = kwargs.pop('target_langs', ['de_DE']) 52 xtm_mock.config['target_languages'] = kwargs.pop('target_langs', ['de_DE'])
53 xtm_mock.config['files'] = kwargs.pop('files', []) 53 xtm_mock.config['files'] = kwargs.pop('files', [])
54 xtm_mock.config['source_language'] = kwargs.pop('source_lang', 'en_US') 54 xtm_mock.config['source_language'] = kwargs.pop('source_lang', 'en_US')
55 xtm_mock.config['workflows'] = [
56 {'name': 'workflow1', 'id': 2222},
57 {'name': 'workflow2', 'id': 3333},
58 ]
55 return xtm_mock.wsgi_app 59 return xtm_mock.wsgi_app
56 60
57 61
58 def _check_auth(): 62 def _check_auth():
59 try: 63 try:
60 auth = request.headers['Authorization'] 64 auth = request.headers['Authorization']
61 except Exception: 65 except Exception:
62 return False 66 return False
63 67
64 if auth != 'XTM-Basic ' + _CREDENTIALS['token_valid']: 68 if auth != 'XTM-Basic ' + _CREDENTIALS['token_valid']:
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 for _ in xtm_mock.config['target_languages'] 266 for _ in xtm_mock.config['target_languages']
263 ] 267 ]
264 268
265 zip_file = create_in_memory_zip(names, data) 269 zip_file = create_in_memory_zip(names, data)
266 return send_file( 270 return send_file(
267 zip_file, 271 zip_file,
268 mimetype='application/zip', 272 mimetype='application/zip',
269 ) 273 )
270 274
271 275
276 @xtm_mock.route('/rest-api/workflows', methods=['GET'])
277 def get_workflows():
278 if not _check_auth():
279 return Response(
280 status=401,
281 response=json.dumps({'reason': 'Authentication failed.'}),
282 )
283
284 name = request.args.get('name')
285 result = []
286
287 for workflow in xtm_mock.config['workflows']:
288 if name in workflow['name']:
289 result.append(workflow)
290
291 return jsonify(result)
292
293
272 if __name__ == '__main__': 294 if __name__ == '__main__':
273 xtm_mock.run(debug=True) 295 xtm_mock.run(debug=True)
OLDNEW
« tests/utils.py ('K') | « tests/utils.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld