Skip to content

Commit 4c9e04c

Browse files
committed
fix: update status code assertions to use HTTP status constants
1 parent d8cb337 commit 4c9e04c

2 files changed

Lines changed: 12 additions & 6 deletions

File tree

tests/api/endpoints/test_heroes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_create_hero(client_with_db: TestClient, session: Session):
2020
def test_create_hero_incomplete(client: TestClient):
2121
# No secret_name
2222
response = client.post("/heroes/", json={"name": "Deadpond"})
23-
assert response.status_code == 422
23+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
2424

2525

2626
def test_create_hero_invalid(client: TestClient):
@@ -32,7 +32,7 @@ def test_create_hero_invalid(client: TestClient):
3232
"secret_name": {"message": "Do you wanna know my secret identity?"},
3333
},
3434
)
35-
assert response.status_code == 422
35+
assert response.status_code == status.HTTP_422_UNPROCESSABLE_ENTITY
3636

3737

3838
def test_read_heroes(session: Session, client_with_db: TestClient):
@@ -45,7 +45,7 @@ def test_read_heroes(session: Session, client_with_db: TestClient):
4545
response = client_with_db.get("/heroes/")
4646
data = response.json()
4747

48-
assert response.status_code == 200
48+
assert response.status_code == status.HTTP_200_OK
4949

5050
assert len(data) == 2
5151
assert data[0]["name"] == hero_1.name
@@ -66,7 +66,7 @@ def test_read_hero(session: Session, client_with_db: TestClient):
6666
response = client_with_db.get(f"/heroes/{hero_1.id}")
6767
data = response.json()
6868

69-
assert response.status_code == 200
69+
assert response.status_code == status.HTTP_200_OK
7070
assert data["name"] == hero_1.name
7171
assert "secret_name" not in data.keys()
7272
assert data["age"] == hero_1.age
@@ -81,7 +81,7 @@ def test_update_hero(session: Session, client_with_db: TestClient):
8181
response = client_with_db.patch(f"/heroes/{hero_1.id}", json={"name": "Deadpuddle"})
8282
data = response.json()
8383

84-
assert response.status_code == 200
84+
assert response.status_code == status.HTTP_200_OK
8585
assert data["name"] == "Deadpuddle"
8686
assert "secret_name" not in data.keys()
8787
assert data["age"] is None
@@ -97,7 +97,7 @@ def test_delete_hero(session: Session, client_with_db: TestClient):
9797

9898
hero_in_db = session.get(Hero, hero_1.id)
9999

100-
assert response.status_code == 200
100+
assert response.status_code == status.HTTP_200_OK
101101
assert hero_in_db is None
102102

103103

tests/api/endpoints/test_users.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def test_create_user(client: TestClient):
4949

5050

5151
def test_create_user_invalid_data(client: TestClient):
52+
# Build raw request dict to bypass Pydantic validation
5253
user_data = {"invalid_field": "NewUser"}
54+
5355
response = client.post(
5456
url="/users/",
5557
headers={"Authorization": settings.API_KEY.get_secret_value()},
@@ -73,7 +75,9 @@ def test_create_user_with_check_success(client: TestClient):
7375

7476

7577
def test_create_user_with_check_reserved_name(client: TestClient):
78+
# Build raw request dict to bypass Pydantic validation
7679
user_data = {"name": "admin"}
80+
7781
response = client.post(
7882
url="/users/check",
7983
headers={"Authorization": settings.API_KEY.get_secret_value()},
@@ -85,7 +89,9 @@ def test_create_user_with_check_reserved_name(client: TestClient):
8589

8690

8791
def test_create_user_with_check_invalid_data(client: TestClient):
92+
# Build raw request dict to bypass Pydantic validation
8893
user_data = {"name": ""}
94+
8995
response = client.post(
9096
url="/users/check",
9197
headers={"Authorization": settings.API_KEY.get_secret_value()},

0 commit comments

Comments
 (0)