aboutsummaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2023-02-16 18:26:12 -0600
committerMichael McVady <femtonaut@gmail.com>2023-02-16 18:26:12 -0600
commitc5cd89c0b21e5bb9a79d445f2ed4630c5bf678f0 (patch)
treec9f44bba8d76ecad0dd26a9ed2bfc5c6c2ce8182 /tests.py
parent4bfab86f636f2392f92037058c783c2634ac2060 (diff)
Fix DELETE and tests
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py43
1 files changed, 33 insertions, 10 deletions
diff --git a/tests.py b/tests.py
index 32511c8..3f800a7 100755
--- a/tests.py
+++ b/tests.py
@@ -1,5 +1,6 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
+import logging
import json
import sys
import uuid
@@ -7,10 +8,13 @@ import uuid
import requests
BASE_URL = "http://localhost:8888"
+DELETE_UUID = "00000000-0000-dddd-0000-000000000000"
POST_UUID = "2dc42f26-884e-4b10-abfb-4fd394aa9d62"
BAD_UUID = "00000000-0000-1111-0000-000000000000"
INVALID_UUID = "0"
+log = logging.getLogger(__name__)
+
def test_redirect():
url = f"{BASE_URL}/asdf"
@@ -100,14 +104,12 @@ def test_json_post_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
+
+ assert r.status_code == 201
+
j = r.json()
- assert len(j) == 1
- assert "title" == j[0]["title"]
- assert "body" == j[0]["body"]
+ assert "Resource created successfully." == j
url = f"{BASE_URL}/posts/{uuid_}"
r = requests.get(url, headers={"Accept": "application/json"})
@@ -119,6 +121,27 @@ def test_json_post_posts():
assert "body" == j[0]["body"]
+def test_json_delete_posts():
+ headers = {"Accept": "application/json"}
+ url = f"{BASE_URL}/posts"
+ uuid_ = DELETE_UUID
+ data = {"id": uuid_, "title": "title", "body": "body"}
+
+ # Create post copy-pasta.
+ r = requests.post(url, headers=headers, json=data)
+ assert r.status_code == 201
+ j = r.json()
+
+ url = f"{BASE_URL}/posts/{uuid_}"
+ r = requests.delete(url, headers=headers)
+ assert r.status_code == 200
+ j = r.json()
+
+ r = requests.get(url, headers=headers)
+ assert r.status_code == 404
+ j = r.json()
+
+
def test_json_get_post_not_found():
url = f"{BASE_URL}/posts/{BAD_UUID}"
r = requests.get(url, headers={"Accept": "application/json"})
@@ -128,7 +151,7 @@ def test_json_get_post_not_found():
assert "Resource not found" in j
url = f"{BASE_URL}/posts/{INVALID_UUID}"
- r = requests.get(url, headers={"Accept": "application/json"})
+ r = requests.delete(url, headers={"Accept": "application/json"})
assert r.status_code == 404
j = r.json()
@@ -143,10 +166,10 @@ def main():
globals()[func]()
except Exception:
winner = False
- print(f"{func} failed.")
+ log.exception(f"🚫 {func} failed 🚫🏆")
if winner:
- print("🏆 You're winner !")
+ log.info("🏆 You're winner !")
if __name__ == "__main__":