File tree Expand file tree Collapse file tree 1 file changed +23
-4
lines changed
Expand file tree Collapse file tree 1 file changed +23
-4
lines changed Original file line number Diff line number Diff line change 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+ )
You can’t perform that action at this time.
0 commit comments