Fixes bug when dealing with empty JSON requests or empty appointment field

When posting a request via requests.post the json field was dumped to json, but it shouldn't have been since requests deals with this internally. That meant that the requests made by the code didn't match proper JSON.
In line with this, the API was only parsing this type POST requests correctly, making add_appointment to fail if a proper formatted JSON was passed.

On top of that, empty appointments were not checked in the Inspector before trying to get data from them, making it crash if a JSON was posted to add_appointment not containing the `appointment` field. Unit tests for this should be added.
This commit is contained in:
Sergi Delgado Segura
2020-03-24 19:55:41 +01:00
parent 6ee04bd303
commit dd53ad68fb
4 changed files with 6 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ def new_appt_data():
def add_appointment(new_appt_data):
r = requests.post(url=add_appointment_endpoint, json=json.dumps(new_appt_data), timeout=5)
r = requests.post(url=add_appointment_endpoint, json=new_appt_data, timeout=5)
if r.status_code == 200:
appointments.append(new_appt_data["appointment"])