Skip to content

Commit

Permalink
✅ [#4908] Add and update tests
Browse files Browse the repository at this point in the history
In the JSON dump docker app, explicitly load the received data before sending again. This prevents the data from being interpreted as a string instead of a JSON object.
  • Loading branch information
viktorvanwijk committed Jan 21, 2025
1 parent 5369dc0 commit 387df52
Show file tree
Hide file tree
Showing 8 changed files with 391 additions and 66 deletions.
7 changes: 5 additions & 2 deletions docker/json-dump/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
from flask import Flask, jsonify, request
import json

from flask import Flask, jsonify, request

app = Flask(__name__)

@app.route("/json_plugin", methods=["POST"])
def json_plugin_post():
data = request.get_json()

app.logger.info(f"Data received: {data}")

message = "No data" if data is None else "Data received"
return jsonify({"message": message, "data": data}), 201
return jsonify({"message": message, "data": json.loads(data)}), 201


@app.route("/test_connection", methods=["GET"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
interactions:
- request:
body: '{"values": {"firstName": "We Are", "auth_bsn": "123456789"}, "schema":
{"$schema": "https://json-schema.org/draft/2020-12/schema", "type": "object",
"properties": {"static_var_1": {"type": "string", "pattern": "^cool_pattern$"},
"form_var_1": {"type": "string"}, "form_var_2": {"type": "string"}, "attachment":
{"type": "string", "contentEncoding": "base64"}}, "required": ["static_var_1",
"form_var_1", "form_var_2"], "additionalProperties": false}}'
body: '"{\"values\": {\"auth_bsn\": \"123456789\", \"firstName\": \"We Are\"},
\"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"type\": \"object\", \"properties\": {\"static_var_1\": {\"type\": \"string\",
\"pattern\": \"^cool_pattern$\"}, \"form_var_1\": {\"type\": \"string\"}, \"form_var_2\":
{\"type\": \"string\"}, \"attachment\": {\"type\": \"string\", \"contentEncoding\":
\"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"],
\"additionalProperties\": false}}"'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzU4MjY2MzksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.8PuPAIY6PI3_g4edfqzFFbHNldYxxRIBjPuAh-p00xk
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk
Connection:
- keep-alive
Content-Length:
- '450'
- '516'
Content-Type:
- application/json
User-Agent:
Expand Down Expand Up @@ -45,7 +46,7 @@ interactions:
Content-Type:
- text/html; charset=utf-8
Date:
- Thu, 02 Jan 2025 14:03:59 GMT
- Tue, 21 Jan 2025 14:31:40 GMT
Server:
- Werkzeug/3.1.3 Python/3.12.8
status:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
interactions:
- request:
body: '"{\"values\": {\"file\": [{\"file_name\": \"file1.txt\", \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\"},
{\"file_name\": \"file2.txt\", \"content\": \"Q29udGVudCBleGFtcGxlIGlzIHRoaXMu\"}]},
\"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"type\": \"object\", \"properties\": {\"static_var_1\": {\"type\": \"string\",
\"pattern\": \"^cool_pattern$\"}, \"form_var_1\": {\"type\": \"string\"}, \"form_var_2\":
{\"type\": \"string\"}, \"attachment\": {\"type\": \"string\", \"contentEncoding\":
\"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"],
\"additionalProperties\": false}}"'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk
Connection:
- keep-alive
Content-Length:
- '638'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.2
method: POST
uri: http://localhost/json_plugin
response:
body:
string: "{\n \"data\": {\n \"schema\": {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n
\ \"additionalProperties\": false,\n \"properties\": {\n \"attachment\":
{\n \"contentEncoding\": \"base64\",\n \"type\": \"string\"\n
\ },\n \"form_var_1\": {\n \"type\": \"string\"\n },\n
\ \"form_var_2\": {\n \"type\": \"string\"\n },\n \"static_var_1\":
{\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n
\ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n
\ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\":
{\n \"file\": [\n {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n
\ \"file_name\": \"file1.txt\"\n },\n {\n \"content\":
\"Q29udGVudCBleGFtcGxlIGlzIHRoaXMu\",\n \"file_name\": \"file2.txt\"\n
\ }\n ]\n }\n },\n \"message\": \"Data received\"\n}\n"
headers:
Connection:
- close
Content-Length:
- '923'
Content-Type:
- application/json
Date:
- Tue, 21 Jan 2025 14:31:40 GMT
Server:
- Werkzeug/3.1.3 Python/3.12.8
status:
code: 201
message: CREATED
version: 1
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
interactions:
- request:
body: '{"values": {"file": "VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu", "firstName": "We
Are", "auth_bsn": "123456789"}, "schema": {"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object", "properties": {"static_var_1": {"type": "string", "pattern":
"^cool_pattern$"}, "form_var_1": {"type": "string"}, "form_var_2": {"type":
"string"}, "attachment": {"type": "string", "contentEncoding": "base64"}}, "required":
["static_var_1", "form_var_1", "form_var_2"], "additionalProperties": false}}'
body: '"{\"values\": {\"file\": []}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"type\": \"object\", \"properties\": {\"static_var_1\": {\"type\": \"string\",
\"pattern\": \"^cool_pattern$\"}, \"form_var_1\": {\"type\": \"string\"}, \"form_var_2\":
{\"type\": \"string\"}, \"attachment\": {\"type\": \"string\", \"contentEncoding\":
\"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"],
\"additionalProperties\": false}}"'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3MzU4MjY2MzksImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.8PuPAIY6PI3_g4edfqzFFbHNldYxxRIBjPuAh-p00xk
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk
Connection:
- keep-alive
Content-Length:
- '494'
- '474'
Content-Type:
- application/json
User-Agent:
Expand All @@ -33,17 +33,16 @@ interactions:
{\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n
\ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n
\ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\":
{\n \"auth_bsn\": \"123456789\",\n \"file\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n
\ \"firstName\": \"We Are\"\n }\n },\n \"message\": \"Data received\"\n}\n"
{\n \"file\": []\n }\n },\n \"message\": \"Data received\"\n}\n"
headers:
Connection:
- close
Content-Length:
- '783'
- '691'
Content-Type:
- application/json
Date:
- Thu, 02 Jan 2025 14:03:59 GMT
- Tue, 21 Jan 2025 14:31:40 GMT
Server:
- Werkzeug/3.1.3 Python/3.12.8
status:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
interactions:
- request:
body: '"{\"values\": {\"file\": null}, \"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"type\": \"object\", \"properties\": {\"static_var_1\": {\"type\": \"string\",
\"pattern\": \"^cool_pattern$\"}, \"form_var_1\": {\"type\": \"string\"}, \"form_var_2\":
{\"type\": \"string\"}, \"attachment\": {\"type\": \"string\", \"contentEncoding\":
\"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"],
\"additionalProperties\": false}}"'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk
Connection:
- keep-alive
Content-Length:
- '476'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.2
method: POST
uri: http://localhost/json_plugin
response:
body:
string: "{\n \"data\": {\n \"schema\": {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n
\ \"additionalProperties\": false,\n \"properties\": {\n \"attachment\":
{\n \"contentEncoding\": \"base64\",\n \"type\": \"string\"\n
\ },\n \"form_var_1\": {\n \"type\": \"string\"\n },\n
\ \"form_var_2\": {\n \"type\": \"string\"\n },\n \"static_var_1\":
{\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n
\ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n
\ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\":
{\n \"file\": null\n }\n },\n \"message\": \"Data received\"\n}\n"
headers:
Connection:
- close
Content-Length:
- '693'
Content-Type:
- application/json
Date:
- Tue, 21 Jan 2025 14:31:40 GMT
Server:
- Werkzeug/3.1.3 Python/3.12.8
status:
code: 201
message: CREATED
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
interactions:
- request:
body: '"{\"values\": {\"file\": [{\"file_name\": \"file1.txt\", \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\"}]},
\"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"type\": \"object\", \"properties\": {\"static_var_1\": {\"type\": \"string\",
\"pattern\": \"^cool_pattern$\"}, \"form_var_1\": {\"type\": \"string\"}, \"form_var_2\":
{\"type\": \"string\"}, \"attachment\": {\"type\": \"string\", \"contentEncoding\":
\"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"],
\"additionalProperties\": false}}"'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk
Connection:
- keep-alive
Content-Length:
- '555'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.2
method: POST
uri: http://localhost/json_plugin
response:
body:
string: "{\n \"data\": {\n \"schema\": {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n
\ \"additionalProperties\": false,\n \"properties\": {\n \"attachment\":
{\n \"contentEncoding\": \"base64\",\n \"type\": \"string\"\n
\ },\n \"form_var_1\": {\n \"type\": \"string\"\n },\n
\ \"form_var_2\": {\n \"type\": \"string\"\n },\n \"static_var_1\":
{\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n
\ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n
\ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\":
{\n \"file\": [\n {\n \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n
\ \"file_name\": \"file1.txt\"\n }\n ]\n }\n },\n
\ \"message\": \"Data received\"\n}\n"
headers:
Connection:
- close
Content-Length:
- '810'
Content-Type:
- application/json
Date:
- Tue, 21 Jan 2025 14:31:40 GMT
Server:
- Werkzeug/3.1.3 Python/3.12.8
status:
code: 201
message: CREATED
version: 1
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
interactions:
- request:
body: '"{\"values\": {\"auth_bsn\": \"123456789\", \"firstName\": \"We Are\",
\"file\": {\"file_name\": \"test_file.txt\", \"content\": \"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\"}},
\"schema\": {\"$schema\": \"https://json-schema.org/draft/2020-12/schema\",
\"type\": \"object\", \"properties\": {\"static_var_1\": {\"type\": \"string\",
\"pattern\": \"^cool_pattern$\"}, \"form_var_1\": {\"type\": \"string\"}, \"form_var_2\":
{\"type\": \"string\"}, \"attachment\": {\"type\": \"string\", \"contentEncoding\":
\"base64\"}}, \"required\": [\"static_var_1\", \"form_var_1\", \"form_var_2\"],
\"additionalProperties\": false}}"'
headers:
Accept:
- '*/*'
Accept-Encoding:
- gzip, deflate, br
Authorization:
- Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiIiLCJpYXQiOjE3Mzc0Njk5MDAsImNsaWVudF9pZCI6IiIsInVzZXJfaWQiOiIiLCJ1c2VyX3JlcHJlc2VudGF0aW9uIjoiIn0.VaaQtoX7c3ac2_Zf8GPvB8fAMYfmJft53c7qXNBY_lk
Connection:
- keep-alive
Content-Length:
- '613'
Content-Type:
- application/json
User-Agent:
- python-requests/2.32.2
method: POST
uri: http://localhost/json_plugin
response:
body:
string: "{\n \"data\": {\n \"schema\": {\n \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n
\ \"additionalProperties\": false,\n \"properties\": {\n \"attachment\":
{\n \"contentEncoding\": \"base64\",\n \"type\": \"string\"\n
\ },\n \"form_var_1\": {\n \"type\": \"string\"\n },\n
\ \"form_var_2\": {\n \"type\": \"string\"\n },\n \"static_var_1\":
{\n \"pattern\": \"^cool_pattern$\",\n \"type\": \"string\"\n
\ }\n },\n \"required\": [\n \"static_var_1\",\n \"form_var_1\",\n
\ \"form_var_2\"\n ],\n \"type\": \"object\"\n },\n \"values\":
{\n \"auth_bsn\": \"123456789\",\n \"file\": {\n \"content\":
\"VGhpcyBpcyBleGFtcGxlIGNvbnRlbnQu\",\n \"file_name\": \"test_file.txt\"\n
\ },\n \"firstName\": \"We Are\"\n }\n },\n \"message\": \"Data
received\"\n}\n"
headers:
Connection:
- close
Content-Length:
- '850'
Content-Type:
- application/json
Date:
- Tue, 21 Jan 2025 14:31:40 GMT
Server:
- Werkzeug/3.1.3 Python/3.12.8
status:
code: 201
message: CREATED
version: 1
Loading

0 comments on commit 387df52

Please sign in to comment.