From a997ec6727b467fd72510a56bfe7a67eb04dbcf9 Mon Sep 17 00:00:00 2001 From: Michael McVady Date: Thu, 26 Oct 2023 23:29:11 -0500 Subject: Remove JSON API --- tests.py | 121 ++------------------------------------------------------------- 1 file changed, 3 insertions(+), 118 deletions(-) (limited to 'tests.py') diff --git a/tests.py b/tests.py index a8050eb..ab3b16a 100755 --- a/tests.py +++ b/tests.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -import json import logging import sys import uuid @@ -79,130 +78,16 @@ def test_html_get_post_not_found(): assert "Resource not found" in text -def test_json_get_post(): - url = f"{POSTS_URL}/{POST_UUID}" - r = requests.get(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 200 - j = r.json() - post = j[0] - assert len(j) == 1 - assert "A Solid Breakdown of the Linux Font Rendering Stack" == post["title"] - assert "hinting and anti-aliasing" in post["body"] - - -def test_json_get_posts(): - url = POSTS_URL - r = requests.get(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 200 - j = r.json() - assert len(j) >= 1 - text = json.dumps(j) - assert "A Solid Breakdown of the Linux Font Rendering Stack" in text - assert "hinting and anti-aliasing" in text - assert "Debugging CGI / CGit" in text - - -def test_json_post_posts(): - url = POSTS_URL - 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"{POSTS_URL}/{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"] - - r = requests.delete(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 200 - j = r.json() - - -def test_json_put_posts(): - url = POSTS_URL - 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"{POSTS_URL}/{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"] - - 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"{POSTS_URL}/{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"] - - r = requests.delete(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 200 - j = r.json() - -def test_json_delete_posts(): - url = POSTS_URL - uuid_ = DELETE_UUID - data = {"id": uuid_, "title": "title", "body": "body"} - - # Create post copy-pasta. - r = requests.post(url, headers=JSON_ACCEPT_HEADER, json=data) - assert r.status_code == 201 - j = r.json() - - url = f"{POSTS_URL}/{uuid_}" - r = requests.delete(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 200 - j = r.json() - - r = requests.get(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 404 - j = r.json() - - -def test_json_get_post_not_found(): - url = f"{POSTS_URL}/{BAD_UUID}" - r = requests.get(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 404 - j = r.json() - assert "Resource not found" in j - - url = f"{POSTS_URL}/{INVALID_UUID}" - r = requests.delete(url, headers=JSON_ACCEPT_HEADER) - assert r.status_code == 404 - j = r.json() - assert "Resource not found" in j - - def main(): winner = True for func in dir(sys.modules[__name__]): if func.startswith("test_"): try: globals()[func]() - except Exception: + except Exception as e: winner = False - log.exception(f"🚫 {func} failed 🚫🏆") - print(f"🚫 {func} failed 🚫🏆") + log.exception(f"🚫 {func} failed {e} 🚫") + print(f"🚫 {func} failed {e} 🚫") if winner: log.info("🏆 You're winner !") -- cgit v1.2.3