flask-demo-api/tests/test_get.py

41 lines
1.2 KiB
Python

import json
def test_get_without_args(client):
response = client.get("/")
assert response.status_code == 400
assert response.get_json() == {
"error": "400 Bad Request: Invalid GET parameters",
}
def test_get_with_wrong_key(client):
response = client.get("/?key=blabla")
assert response.status_code == 404
assert response.get_json() == {
"error": "404 Not Found: Key not found",
}
def test_get_with_existing_key(client):
response = client.get("/?key=abcd")
assert response.status_code == 404
assert response.get_json() == {
"error": "404 Not Found: Key not found",
}
data = json.dumps({"key": "abcd", "val": "def"})
response = client.post("/", data=data, content_type="application/json")
assert response.status_code == 201
response = client.get("/?key=abcd")
assert response.status_code == 200
assert response.get_json() == {"message": "Ok", "data": json.loads(data)}
client.delete("/", data=data, content_type="application/json")
response = client.get("/?key=abcd")
assert response.status_code == 404
assert response.get_json() == {
"error": "404 Not Found: Key not found",
}