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

Side by Side Diff: tests/crowdin_mock_api.py

Issue 29693633: Noissue - Add crowdin api config support (Closed) Base URL: https://hg.adblockplus.org/cms
Patch Set: address PS4 comments Created March 6, 2018, 2:28 a.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 | « no previous file | tests/test_translations.py » ('j') | 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
2
1 from flask import Flask, send_from_directory, jsonify, request 3 from flask import Flask, send_from_directory, jsonify, request
2 4
3 app = Flask(__name__) 5 app = Flask('mock_api')
4 app.request_log = [] 6
7
8 def load(rootdir, zipdir):
9 app.request_log = []
10 app.config['zipdir'] = zipdir
11 app.config['info'] = {'files': [], 'languages': []}
12 app.config['supported_languages'] = []
13 for root, locales, files in os.walk(rootdir):
14 for locale in locales:
15 files = []
16 app.config['supported_languages'].append({
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(
19 {'code': locale, 'can_translate': 1, 'can_approve': 1})
20
21 for translations in os.listdir(os.path.join(root, locale)):
22 files.append({'name': translations, 'node_type': 'file'})
23
24 app.config['info']['files'].append({'name': locale,
25 'files': files,
26 'node_type': 'directory'})
27 return app
5 28
6 29
7 @app.before_request 30 @app.before_request
8 def log_request_info(): 31 def log_request_info():
9 log = (request.url, str(request.get_data())) 32 app.request_log.append((request.url, str(request.get_data())))
10 app.request_log.append(log)
11 33
12 34
13 @app.route('/api/project/test/info', methods=['GET']) 35 @app.route('/api/project/test/info', methods=['GET'])
14 def info(): 36 def info():
15 return jsonify( 37 return jsonify(app.config['info'])
16 {
17 'languages': [
18 {
19 'name': 'German',
20 'code': 'de',
21 'can_translate': 1,
22 'can_approve': 1,
23 38
24 },
25 {
26 'name': 'English',
27 'code': 'en',
28 'can_translate': 1,
29 'can_approve': 1,
30 39
31 }, 40 @app.route('/api/project/test/edit-project', methods=['POST'])
32 41 def edit():
33 ], 42 return jsonify()
34 'files': [
35 {
36 'node_type': 'directory',
37 'name': 'en',
38 'files': [
39 {
40 'node_type': 'file',
41 'name': 'translate.json',
42 'created': '2016-09-26 08:30:07',
43 'last_updated': '2016-09-26 08:30:08',
44 'last_accessed': None,
45 'last_revision': '1'
46 },
47 ]
48 },
49 {
50 'node_type': 'directory',
51 'name': 'de',
52 'files': [
53 {
54 'node_type': 'file',
55 'name': 'translate.json',
56 'created': '2016-09-26 08:30:07',
57 'last_updated': '2016-09-26 08:30:08',
58 'last_accessed': None,
59 'last_revision': '1'
60 }
61 ]
62 }
63 ]
64 }
65 )
66 43
67 44
68 @app.route('/api/project/test/supported-languages', methods=['GET']) 45 @app.route('/api/project/test/supported-languages', methods=['GET'])
69 def supported_langs(): 46 def supported_langs():
70 return jsonify( 47 return jsonify(app.config['supported_languages'])
71 [
72 {
73 'name': 'German',
74 'crowdin_code': 'de',
75 'editor_code': 'de',
76 'iso_639_1': 'de',
77 'iso_639_3': 'deu',
78 'locale': 'de-DE'
79 },
80 {
81 'name': 'English',
82 'crowdin_code': 'en',
83 'editor_code': 'en',
84 'iso_639_1': 'en',
85 'iso_639_3': 'eng',
86 'locale': 'en-US'
87 },
88 ]
89 )
90 48
91 49
92 @app.route('/api/project/test/add-file', methods=['POST']) 50 @app.route('/api/project/test/add-file', methods=['POST'])
93 def add_file(): 51 def add_file():
94 app.string = request.get_data() 52 app.string = request.get_data()
95 return jsonify() 53 return jsonify()
96 54
97 55
98 @app.route('/api/project/test/upload-translation', methods=['POST']) 56 @app.route('/api/project/test/upload-translation', methods=['POST'])
99 def upload_translation(): 57 def upload_translation():
(...skipping 10 matching lines...) Expand all
110 return jsonify() 68 return jsonify()
111 69
112 70
113 @app.route('/api/project/test/export', methods=['GET']) 71 @app.route('/api/project/test/export', methods=['GET'])
114 def export(): 72 def export():
115 return jsonify({'success': {'status': 'skipped'}}) 73 return jsonify({'success': {'status': 'skipped'}})
116 74
117 75
118 @app.route('/api/project/test/download/all.zip', methods=['GET']) 76 @app.route('/api/project/test/download/all.zip', methods=['GET'])
119 def get_zip(): 77 def get_zip():
120 return send_from_directory('', 'all.zip') 78 return send_from_directory(app.config['zipdir'], 'all.zip')
OLDNEW
« no previous file with comments | « no previous file | tests/test_translations.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld