diff options
author | Michael McVady <femtonaut@gmail.com> | 2023-10-26 23:29:11 -0500 |
---|---|---|
committer | Michael McVady <femtonaut@gmail.com> | 2023-10-26 23:34:42 -0500 |
commit | a997ec6727b467fd72510a56bfe7a67eb04dbcf9 (patch) | |
tree | bbd1babe15bb83db10d831061a4dd5110638589c /tests.py | |
parent | e24dfc3412648c8b07a32a59774ed21f5058f7e0 (diff) |
Remove JSON API
Diffstat (limited to 'tests.py')
-rwxr-xr-x | tests.py | 121 |
1 files changed, 3 insertions, 118 deletions
@@ -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 !") |