diff options
Diffstat (limited to 'tests.py')
-rwxr-xr-x | tests.py | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -2,6 +2,7 @@ import json import sys +import uuid import requests @@ -94,6 +95,30 @@ def test_json_get_posts(): assert "Debugging CGI / CGit" in text +def test_json_post_posts(): + url = f"{BASE_URL}/posts" + uuid_ = str(uuid.uuid4()) + data = {"id": uuid_, "title": "title", "body": "body"} + r = requests.post(url, headers={"Accept": "application/json"}, json=data) + # FIXME need to refactor to fix status code here. + # assert r.status_code == 201 + assert r.status_code == 200 + j = r.json() + + assert len(j) == 1 + assert "title" == j[0]["title"] + assert "body" == j[0]["body"] + + url = f"{BASE_URL}/posts/{uuid_}" + r = requests.get(url, headers={"Accept": "application/json"}) + assert r.status_code == 200 + j = r.json() + + assert len(j) == 1 + assert "title" == j[0]["title"] + assert "body" == j[0]["body"] + + def test_json_get_post_not_found(): url = f"{BASE_URL}/posts/{BAD_UUID}" r = requests.get(url, headers={"Accept": "application/json"}) |