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

Side by Side Diff: tests/mock_api.py

Issue 29355396: Issue 4380 - Add Mock Crowdin API and Sync Test (Closed)
Patch Set: Add basic assertion for sync test Created Oct. 5, 2016, 3:50 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
OLDNEW
(Empty)
1 from flask import Flask, send_from_directory, jsonify, request
Sebastian Noack 2016/10/05 12:06:16 I wonder whether using Flask here would be overkil
Sebastian Noack 2016/10/05 12:06:16 The name of this module is a little to generic, gi
Jon Sonesen 2016/10/05 14:38:13 I am aware that Flask is implemented on top of Wer
Jon Sonesen 2016/10/05 14:38:13 yes that is a good point and I will do so.
Sebastian Noack 2016/10/05 16:36:44 Werkzeug might not be as low-level as you think. I
Jon Sonesen 2016/10/08 02:21:40 I see, I think that if you are okay with it that s
2
3 app = Flask(__name__)
4 app.request_data = {}
Jon Sonesen 2016/10/05 03:54:49 This is my preliminary solution to the logging pro
Vasily Kuznetsov 2016/10/05 14:44:42 Perhaps it would make more sense to make this a li
Jon Sonesen 2016/10/08 02:21:40 I agree here. Will do!
5
6
7 @app.before_request
8 def log_request_info():
9 data = request.get_data()
10 if data:
11 app.request_data[request.url] = data
12
13
14 @app.route('/api/project/test/info', methods=['GET'])
15 def info():
16 return jsonify(
17 {
18 'languages': [
19 {
20 'name': 'German',
21 'code': 'de',
22 'can_translate': 1,
23 'can_approve': 1,
24
25 },
26 {
27 'name': 'English',
28 'code': 'en',
29 'can_translate': 1,
30 'can_approve': 1,
31
32 },
33
34 ],
35 'files': [
36 {
37 'node_type': 'directory',
38 'name': 'en',
39 'files': [
40 {
41 'node_type': 'file',
42 'name': 'translate.json',
43 'created': '2016-09-26 08:30:07',
44 'last_updated': '2016-09-26 08:30:08',
45 'last_accessed': None,
46 'last_revision': '1'
47 },
48 ]
49 },
50 {
51 'node_type': 'directory',
52 'name': 'de',
53 'files': [
54 {
55 'node_type': 'file',
56 'name': 'translate.json',
57 'created': '2016-09-26 08:30:07',
58 'last_updated': '2016-09-26 08:30:08',
59 'last_accessed': None,
60 'last_revision': '1'
61 }
62 ]
63 }
64 ]
65 }
66 )
67
68
69 @app.route('/api/project/test/supported-languages', methods=['GET'])
70 def supported_langs():
71 return jsonify(
72 [
73 {
74 'name': 'German',
75 'crowdin_code': 'de',
76 'editor_code': 'de',
77 'iso_639_1': 'de',
78 'iso_639_3': 'deu',
79 'locale': 'de-DE'
80 },
81 {
82 'name': 'English',
83 'crowdin_code': 'en',
84 'editor_code': 'en',
85 'iso_639_1': 'en',
86 'iso_639_3': 'eng',
87 'locale': 'en-US'
88 },
89 ]
90 )
91
92
93 @app.route('/api/project/test/add-file', methods=['POST'])
94 def add_file():
95 app.string = request.get_data()
96 return jsonify()
97
98
99 @app.route('/api/project/test/upload-translation', methods=['POST'])
100 def upload_translation():
101 return jsonify()
102
103
104 @app.route('/api/project/test/delete-directory', methods=['POST'])
105 def delete_directory():
106 return jsonify()
107
108
109 @app.route('/api/project/test/delete-file', methods=['POST'])
110 def delete_file():
111 return jsonify()
112
113
114 @app.route('/api/project/test/export', methods=['GET'])
115 def export():
116 return jsonify(
117 {
118 'success': {
119 'status': 'skipped'
120 }
121 },
122 )
123
124
125 @app.route('/api/project/test/download/all.zip', methods=['GET'])
126 def get_zip():
127 return send_from_directory('', 'all.zip')
OLDNEW

Powered by Google App Engine
This is Rietveld