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

Delta Between Two Patch Sets: tests/crowdin_mock_api.py

Issue 29693633: Noissue - Add crowdin api config support (Closed) Base URL: https://hg.adblockplus.org/cms
Left Patch Set: address PS4 comments Created March 6, 2018, 2:28 a.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 | « no previous file | tests/test_translations.py » ('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 2
3 from flask import Flask, send_from_directory, jsonify, request 3 from flask import Flask, send_from_directory, jsonify, request
4 4
5 app = Flask('mock_api') 5 app = Flask('mock_api')
6 6
7 7
8 def load(rootdir, zipdir): 8 def load(rootdir, zipdir):
9 app.request_log = [] 9 app.request_log = []
10 app.config['zipdir'] = zipdir 10 app.config['zipdir'] = zipdir
11 app.config['info'] = {'files': [], 'languages': []} 11 app.config['info'] = {'files': [], 'languages': []}
12 app.config['supported_languages'] = [] 12 app.config['supported_languages'] = []
13
13 for root, locales, files in os.walk(rootdir): 14 for root, locales, files in os.walk(rootdir):
14 for locale in locales: 15 for locale in locales:
15 files = [] 16 files = []
16 app.config['supported_languages'].append({ 17 app.config['supported_languages'].append({'crowdin_code': locale})
Vasily Kuznetsov 2018/03/06 11:17:36 I would suggest reformatting the dicts that don't
Jon Sonesen 2018/03/08 19:13:10 Done.
17 'crowdin_code': locale}) 18 app.config['info']['languages'].append({
18 app.config['info']['languages'].append( 19 'code': locale,
19 {'code': locale, 'can_translate': 1, 'can_approve': 1}) 20 'can_translate': 1,
21 'can_approve': 1,
22 })
20 23
21 for translations in os.listdir(os.path.join(root, locale)): 24 for translations in os.listdir(os.path.join(root, locale)):
22 files.append({'name': translations, 'node_type': 'file'}) 25 files.append({'name': translations, 'node_type': 'file'})
23 26
24 app.config['info']['files'].append({'name': locale, 27 app.config['info']['files'].append({
25 'files': files, 28 'name': locale,
26 'node_type': 'directory'}) 29 'files': files,
30 'node_type': 'directory',
31 })
32
27 return app 33 return app
28 34
29 35
30 @app.before_request 36 @app.before_request
31 def log_request_info(): 37 def log_request_info():
32 app.request_log.append((request.url, str(request.get_data()))) 38 app.request_log.append((request.url, str(request.get_data())))
33 39
34 40
35 @app.route('/api/project/test/info', methods=['GET']) 41 @app.route('/api/project/test/info', methods=['GET'])
36 def info(): 42 def info():
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 75
70 76
71 @app.route('/api/project/test/export', methods=['GET']) 77 @app.route('/api/project/test/export', methods=['GET'])
72 def export(): 78 def export():
73 return jsonify({'success': {'status': 'skipped'}}) 79 return jsonify({'success': {'status': 'skipped'}})
74 80
75 81
76 @app.route('/api/project/test/download/all.zip', methods=['GET']) 82 @app.route('/api/project/test/download/all.zip', methods=['GET'])
77 def get_zip(): 83 def get_zip():
78 return send_from_directory(app.config['zipdir'], 'all.zip') 84 return send_from_directory(app.config['zipdir'], 'all.zip')
LEFTRIGHT

Powered by Google App Engine
This is Rietveld