From 93a0f7734eed6bbacbf67278ada57690d3525013 Mon Sep 17 00:00:00 2001 From: Santiago Garcia Arango Date: Sun, 25 Feb 2024 21:29:11 -0500 Subject: [PATCH] Update unit tests to match new endpoints --- tests/unit/lambdas/api/test_main.py | 35 ++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/unit/lambdas/api/test_main.py b/tests/unit/lambdas/api/test_main.py index 7c96665..8f91eea 100755 --- a/tests/unit/lambdas/api/test_main.py +++ b/tests/unit/lambdas/api/test_main.py @@ -10,7 +10,36 @@ def test_read_root(): assert response.json() == {"message": "Hello by Santi"} -def test_read_status(): - response = client.get("/status") +def test_read_status_no_query(): + response = client.get("/items/123") assert response.status_code == 200 - assert response.json() == {"status": "OK"} + assert response.json() == {"item_id": 123, "q": None} + + +def test_read_status_with_query(): + response = client.get("/items/456?q=Santi") + assert response.status_code == 200 + assert response.json() == {"item_id": 456, "q": "Santi"} + + +def test_update_item_success(): + response = client.put( + "/items/789", + json={ + "name": "test name", + "price": 99.9, + }, + ) + assert response.status_code == 200 + assert response.json() == {"item_name": "test name", "item_id": 789} + + +def test_update_item_wrong_payload(): + response = client.put( + "/items/789", + json={ + "name": "test name", + "amount": 99.9, # Intentionally wrong key (not in model) + }, + ) + assert response.status_code == 422