aboutsummaryrefslogtreecommitdiff
path: root/tests.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests.py')
-rwxr-xr-xtests.py50
1 files changed, 26 insertions, 24 deletions
diff --git a/tests.py b/tests.py
index 0f73563..a8050eb 100755
--- a/tests.py
+++ b/tests.py
@@ -1,13 +1,16 @@
#!/usr/bin/env python3
-
import json
import logging
import sys
import uuid
+from typing import Dict, List, Optional
import requests
BASE_URL = "http://localhost:8888"
+POSTS_URL = f"{BASE_URL}/posts"
+
+
DELETE_UUID = "00000000-0000-dddd-0000-000000000000"
POST_UUID = "6d011855-6b0d-4202-a243-4d9db9807f14"
BAD_UUID = "00000000-0000-1111-0000-000000000000"
@@ -19,14 +22,6 @@ 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)
@@ -36,7 +31,7 @@ def test_redirect():
def test_html_get_post():
- url = f"{BASE_URL}/posts/{POST_UUID}"
+ url = f"{POSTS_URL}/{POST_UUID}"
r = requests.get(url)
assert r.status_code == 200
text = r.text
@@ -58,7 +53,7 @@ def test_html_get_base_url():
def test_html_get_posts():
- url = f"{BASE_URL}/posts"
+ url = POSTS_URL
r = requests.get(url)
assert r.status_code == 200
text = r.text
@@ -69,14 +64,14 @@ def test_html_get_posts():
def test_html_get_post_not_found():
- url = f"{BASE_URL}/posts/{BAD_UUID}"
+ url = f"{POSTS_URL}/{BAD_UUID}"
r = requests.get(url)
assert r.status_code == 404
text = r.text
assert "Resource not found" in text
- url = f"{BASE_URL}/posts/{INVALID_UUID}"
+ url = f"{POSTS_URL}/{INVALID_UUID}"
r = requests.get(url)
assert r.status_code == 404
text = r.text
@@ -85,7 +80,7 @@ def test_html_get_post_not_found():
def test_json_get_post():
- url = f"{BASE_URL}/posts/{POST_UUID}"
+ url = f"{POSTS_URL}/{POST_UUID}"
r = requests.get(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 200
j = r.json()
@@ -96,7 +91,7 @@ def test_json_get_post():
def test_json_get_posts():
- url = f"{BASE_URL}/posts"
+ url = POSTS_URL
r = requests.get(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 200
j = r.json()
@@ -108,7 +103,7 @@ def test_json_get_posts():
def test_json_post_posts():
- url = f"{BASE_URL}/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)
@@ -116,7 +111,7 @@ def test_json_post_posts():
j = r.json()
assert "Resource created successfully." == j
- url = f"{BASE_URL}/posts/{uuid_}"
+ url = f"{POSTS_URL}/{uuid_}"
r = requests.get(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 200
j = r.json()
@@ -124,9 +119,13 @@ def test_json_post_posts():
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 = f"{BASE_URL}/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)
@@ -134,7 +133,7 @@ def test_json_put_posts():
j = r.json()
assert "Resource created successfully." == j
- url = f"{BASE_URL}/posts/{uuid_}"
+ url = f"{POSTS_URL}/{uuid_}"
r = requests.get(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 200
j = r.json()
@@ -148,7 +147,7 @@ def test_json_put_posts():
j = r.json()
assert "OK" == j
- url = f"{BASE_URL}/posts/{uuid_}"
+ url = f"{POSTS_URL}/{uuid_}"
r = requests.get(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 200
j = r.json()
@@ -156,9 +155,12 @@ def test_json_put_posts():
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 = f"{BASE_URL}/posts"
+ url = POSTS_URL
uuid_ = DELETE_UUID
data = {"id": uuid_, "title": "title", "body": "body"}
@@ -167,7 +169,7 @@ def test_json_delete_posts():
assert r.status_code == 201
j = r.json()
- url = f"{BASE_URL}/posts/{uuid_}"
+ url = f"{POSTS_URL}/{uuid_}"
r = requests.delete(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 200
j = r.json()
@@ -178,13 +180,13 @@ def test_json_delete_posts():
def test_json_get_post_not_found():
- url = f"{BASE_URL}/posts/{BAD_UUID}"
+ 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"{BASE_URL}/posts/{INVALID_UUID}"
+ url = f"{POSTS_URL}/{INVALID_UUID}"
r = requests.delete(url, headers=JSON_ACCEPT_HEADER)
assert r.status_code == 404
j = r.json()