Index: tests/mock_api.py |
=================================================================== |
new file mode 100644 |
--- /dev/null |
+++ b/tests/mock_api.py |
@@ -0,0 +1,127 @@ |
+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
|
+ |
+app = Flask(__name__) |
+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!
|
+ |
+ |
+@app.before_request |
+def log_request_info(): |
+ data = request.get_data() |
+ if data: |
+ app.request_data[request.url] = data |
+ |
+ |
+@app.route('/api/project/test/info', methods=['GET']) |
+def info(): |
+ return jsonify( |
+ { |
+ 'languages': [ |
+ { |
+ 'name': 'German', |
+ 'code': 'de', |
+ 'can_translate': 1, |
+ 'can_approve': 1, |
+ |
+ }, |
+ { |
+ 'name': 'English', |
+ 'code': 'en', |
+ 'can_translate': 1, |
+ 'can_approve': 1, |
+ |
+ }, |
+ |
+ ], |
+ 'files': [ |
+ { |
+ 'node_type': 'directory', |
+ 'name': 'en', |
+ 'files': [ |
+ { |
+ 'node_type': 'file', |
+ 'name': 'translate.json', |
+ 'created': '2016-09-26 08:30:07', |
+ 'last_updated': '2016-09-26 08:30:08', |
+ 'last_accessed': None, |
+ 'last_revision': '1' |
+ }, |
+ ] |
+ }, |
+ { |
+ 'node_type': 'directory', |
+ 'name': 'de', |
+ 'files': [ |
+ { |
+ 'node_type': 'file', |
+ 'name': 'translate.json', |
+ 'created': '2016-09-26 08:30:07', |
+ 'last_updated': '2016-09-26 08:30:08', |
+ 'last_accessed': None, |
+ 'last_revision': '1' |
+ } |
+ ] |
+ } |
+ ] |
+ } |
+ ) |
+ |
+ |
+@app.route('/api/project/test/supported-languages', methods=['GET']) |
+def supported_langs(): |
+ return jsonify( |
+ [ |
+ { |
+ 'name': 'German', |
+ 'crowdin_code': 'de', |
+ 'editor_code': 'de', |
+ 'iso_639_1': 'de', |
+ 'iso_639_3': 'deu', |
+ 'locale': 'de-DE' |
+ }, |
+ { |
+ 'name': 'English', |
+ 'crowdin_code': 'en', |
+ 'editor_code': 'en', |
+ 'iso_639_1': 'en', |
+ 'iso_639_3': 'eng', |
+ 'locale': 'en-US' |
+ }, |
+ ] |
+ ) |
+ |
+ |
+@app.route('/api/project/test/add-file', methods=['POST']) |
+def add_file(): |
+ app.string = request.get_data() |
+ return jsonify() |
+ |
+ |
+@app.route('/api/project/test/upload-translation', methods=['POST']) |
+def upload_translation(): |
+ return jsonify() |
+ |
+ |
+@app.route('/api/project/test/delete-directory', methods=['POST']) |
+def delete_directory(): |
+ return jsonify() |
+ |
+ |
+@app.route('/api/project/test/delete-file', methods=['POST']) |
+def delete_file(): |
+ return jsonify() |
+ |
+ |
+@app.route('/api/project/test/export', methods=['GET']) |
+def export(): |
+ return jsonify( |
+ { |
+ 'success': { |
+ 'status': 'skipped' |
+ } |
+ }, |
+ ) |
+ |
+ |
+@app.route('/api/project/test/download/all.zip', methods=['GET']) |
+def get_zip(): |
+ return send_from_directory('', 'all.zip') |