aboutsummaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2023-07-08 14:09:04 -0500
committerMichael McVady <femtonaut@gmail.com>2023-07-08 14:09:04 -0500
commitb1d89102b08217e8dd2dad1ab210f052a138d1f5 (patch)
treea7014b4909e3c70b9a7553736c25235cb2aa2f8e /tests.py
parent26be9c37aaee44f31a852da46b07032577db6fc8 (diff)
Fix `tests.py`
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py47
1 files changed, 44 insertions, 3 deletions
diff --git a/tests.py b/tests.py
index f07b397..0f73563 100755
--- a/tests.py
+++ b/tests.py
@@ -9,7 +9,7 @@ import requests
BASE_URL = "http://localhost:8888"
DELETE_UUID = "00000000-0000-dddd-0000-000000000000"
-POST_UUID = "2dc42f26-884e-4b10-abfb-4fd394aa9d62"
+POST_UUID = "6d011855-6b0d-4202-a243-4d9db9807f14"
BAD_UUID = "00000000-0000-1111-0000-000000000000"
INVALID_UUID = "0"
@@ -19,11 +19,19 @@ log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
+# def test_health():
+# url = f"{BASE_URL}/health"
+# r = requests.get(url)
+# assert r.status_code == 200
+# text = r.text
+# assert "OK" in text
+
+
def test_redirect():
url = f"{BASE_URL}/asdf"
r = requests.get(url, allow_redirects=False)
- assert r.status_code == 301
+ assert r.status_code == 307
assert r.headers["Location"] == "/"
@@ -101,7 +109,26 @@ def test_json_get_posts():
def test_json_post_posts():
url = f"{BASE_URL}/posts"
- data = {"id": str(uuid.uuid4()), "title": "title", "body": "body"}
+ uuid_ = str(uuid.uuid4())
+ data = {"id": uuid_, "title": "title", "body": "body"}
+ r = requests.post(url, headers=JSON_ACCEPT_HEADER, json=data)
+ assert r.status_code == 201
+ j = r.json()
+ assert "Resource created successfully." == j
+
+ url = f"{BASE_URL}/posts/{uuid_}"
+ r = requests.get(url, headers=JSON_ACCEPT_HEADER)
+ 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_put_posts():
+ url = f"{BASE_URL}/posts"
+ uuid_ = str(uuid.uuid4())
+ data = {"id": uuid_, "title": "title", "body": "body"}
r = requests.post(url, headers=JSON_ACCEPT_HEADER, json=data)
assert r.status_code == 201
j = r.json()
@@ -115,6 +142,20 @@ def test_json_post_posts():
assert "title" == j[0]["title"]
assert "body" == j[0]["body"]
+ data = {"title": "title2", "body": "body2"}
+ r = requests.put(url, headers=JSON_ACCEPT_HEADER, json=data)
+ assert r.status_code == 200
+ j = r.json()
+ assert "OK" == j
+
+ url = f"{BASE_URL}/posts/{uuid_}"
+ r = requests.get(url, headers=JSON_ACCEPT_HEADER)
+ assert r.status_code == 200
+ j = r.json()
+ assert len(j) == 1
+ assert "title2" == j[0]["title"]
+ assert "body2" == j[0]["body"]
+
def test_json_delete_posts():
url = f"{BASE_URL}/posts"