diff options
-rw-r--r-- | README.md | 16 | ||||
-rwxr-xr-x | tests.py | 47 |
2 files changed, 53 insertions, 10 deletions
@@ -38,14 +38,16 @@ Use `psql` and load `db/db.sql` for models, ## TODO -1. Have `tests.py` load and drop database. 1. ~Only do HTTP stuff at the edge.~ -1. `PUT`/`PATCH`? posts. -1. pagination -1. HTML form for edits -1. Make h1 first class markdown citizen, (remove title) -1. Remove JSON API? -1. use sha256 hash to check kore blob +2. ~`PUT`~/`PATCH`? posts. +3. pagination +4. HTML form for edits +5. Make h1 first class markdown citizen, (remove title) +6. Remove JSON API? +7. use sha256 hash to check kore blob +8. Have `tests.py` load and drop database. +9. Refactor URLs and HTTP calls in tests `tests.py` to reduce copy-pasta +10. Get rid of `requests` dependency in `tests.py` ## C? @@ -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" |