Compare commits
2 Commits
ef66f332ef
...
e17a90c7c3
Author | SHA1 | Date | |
---|---|---|---|
![]() |
e17a90c7c3 | ||
![]() |
8abb01f120 |
@ -1,18 +0,0 @@
|
|||||||
from fastapi.testclient import TestClient
|
|
||||||
from main import app
|
|
||||||
|
|
||||||
client = TestClient(app)
|
|
||||||
|
|
||||||
|
|
||||||
def test_failing_root():
|
|
||||||
# This will fail because of the wrong expected message
|
|
||||||
response = client.get("/")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert response.json() == {"message": "Wrong Message"}
|
|
||||||
|
|
||||||
|
|
||||||
def test_failing_item():
|
|
||||||
# This will fail because of the missing field assertion
|
|
||||||
response = client.get("/items/99")
|
|
||||||
assert response.status_code == 200
|
|
||||||
assert "nonexistent_field" in response.json()
|
|
16
tests/test_success.py
Normal file
16
tests/test_success.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from fastapi.testclient import TestClient
|
||||||
|
from main import app
|
||||||
|
|
||||||
|
client = TestClient(app)
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_root():
|
||||||
|
response = client.get("/")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"message": "Hello BackendIM"}
|
||||||
|
|
||||||
|
|
||||||
|
def test_read_item():
|
||||||
|
response = client.get("/items/42")
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.json() == {"item_id": 42, "message": "Item details"}
|
Loading…
x
Reference in New Issue
Block a user