From 850df3b8721963b6fefc226b533c347cde79ff25 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Fri, 6 Jan 2023 06:31:15 -0600 Subject: Hack in POST handling; needs refactoring --- tests.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'tests.py') diff --git a/tests.py b/tests.py index 533d2c2..33c9f6d 100755 --- a/tests.py +++ b/tests.py @@ -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"}) -- cgit v1.2.3