1313CUSTOMERS_ENDPOINT = "/context/customers"
1414
1515
16+ @pytest .fixture
17+ def mock_transaction (mocker : MockerFixture ) -> AsyncMock :
18+ mock_transaction : AsyncMock = mocker .patch (
19+ "app.db.database_config.database.transaction"
20+ )
21+ return mock_transaction
22+
23+
1624@pytest .fixture
1725def mock_execute (mocker : MockerFixture ) -> AsyncMock :
1826 mock_execute : AsyncMock = mocker .patch ("app.db.database_config.database.execute" )
@@ -35,15 +43,19 @@ def mock_fetch_all(mocker: MockerFixture) -> AsyncMock:
3543 return mock_fetch_all
3644
3745
38- def test_customers_delete (mock_execute : AsyncMock , test_client : TestClient ):
46+ def test_customers_delete (
47+ mock_transaction : AsyncMock , mock_execute : AsyncMock , test_client : TestClient
48+ ):
3949 response : Response = test_client .delete (CUSTOMERS_ENDPOINT )
4050 assert_that (response .status_code ).is_equal_to (204 )
4151
4252 assert len (mock_execute .call_args_list ) == 1
4353 assert mock_execute .call_args .kwargs ["query" ] == "TRUNCATE TABLE CUSTOMERS"
4454
4555
46- def test_customers_insert (mock_execute_many : AsyncMock , test_client : TestClient ):
56+ def test_customers_insert (
57+ mock_transaction : AsyncMock , mock_execute_many : AsyncMock , test_client : TestClient
58+ ):
4759 customer1 = Customer (first_name = "fname1" , last_name = "lname1" )
4860 customer2 = Customer (first_name = "fname2" , last_name = "lname2" )
4961 input_json = jsonable_encoder ([customer1 , customer2 ])
@@ -61,7 +73,9 @@ def test_customers_insert(mock_execute_many: AsyncMock, test_client: TestClient)
6173 assert_that (inserted_rows ).contains (jsonable_encoder (customer2 ))
6274
6375
64- def test_customers_read (mock_fetch_all : AsyncMock , test_client : TestClient ):
76+ def test_customers_read (
77+ mock_transaction : AsyncMock , mock_fetch_all : AsyncMock , test_client : TestClient
78+ ):
6579 customer1 = Customer (first_name = "fname1" , last_name = "lname1" )
6680 customer2 = Customer (first_name = "fname2" , last_name = "lname2" )
6781
0 commit comments