2024-04-16 04:48:10 +03:00
|
|
|
import json
|
|
|
|
|
|
|
|
|
2024-04-16 01:03:02 +03:00
|
|
|
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",
|
|
|
|
}
|
2024-04-16 04:48:10 +03:00
|
|
|
|
|
|
|
|
|
|
|
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",
|
|
|
|
}
|