Skip to content

Commit a1f3085

Browse files
More unit tests
1 parent 7fa5122 commit a1f3085

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

tests_unit/routers/test_customer.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,32 @@
88

99

1010
@pytest.fixture
11-
def mock_database_execute(mocker: MockerFixture) -> AsyncMock:
11+
def mock_execute(mocker: MockerFixture) -> AsyncMock:
1212
mock_execute: AsyncMock = mocker.patch("app.db.database_config.database.execute")
1313
return mock_execute
1414

1515

16-
def test_customers_insert_read_delete(
17-
mock_database_execute: AsyncMock, test_client: TestClient
18-
):
16+
@pytest.fixture
17+
def mock_execute_many(mocker: MockerFixture) -> AsyncMock:
18+
mock_execute_many: AsyncMock = mocker.patch(
19+
"app.db.database_config.database.execute_many"
20+
)
21+
return mock_execute_many
22+
23+
24+
def test_customers_delete(mock_execute: AsyncMock, test_client: TestClient):
1925
initial_delete: Response = test_client.delete("/context/customers")
2026
assert_that(initial_delete.status_code).is_equal_to(204)
27+
28+
assert len(mock_execute.call_args_list) == 1
29+
assert mock_execute.call_args.kwargs["query"] == "TRUNCATE TABLE CUSTOMERS"
30+
31+
32+
def test_customers_insert(mock_execute_many: AsyncMock, test_client: TestClient):
33+
initial_delete: Response = test_client.put("/context/customers", json=[])
34+
assert_that(initial_delete.status_code).is_equal_to(204)
35+
36+
assert len(mock_execute_many.call_args_list) == 1
37+
assert_that(mock_execute_many.call_args.kwargs["query"]).is_equal_to(
38+
"INSERT INTO CUSTOMERS(FIRST_NAME, LAST_NAME) VALUES (:first_name, :last_name)"
39+
)

0 commit comments

Comments
 (0)