11import pytest
2- from botocore .stub import Stubber
32
43from app .routes .posts import table
54
65
7- @pytest .fixture
8- def mock_dynamodb ():
9- with Stubber (table .meta .client ) as stubber :
10- yield stubber
11- stubber .assert_no_pending_responses ()
12-
13-
6+ @pytest .mark .parametrize ("mock_dynamodb" , [table ], indirect = True )
147def test_read_posts (client , mock_dynamodb ):
158 mock_dynamodb .add_response (
169 "scan" ,
@@ -34,6 +27,7 @@ def test_read_posts(client, mock_dynamodb):
3427 ]
3528
3629
30+ @pytest .mark .parametrize ("mock_dynamodb" , [table ], indirect = True )
3731def test_read_post (client , mock_dynamodb ):
3832 mock_dynamodb .add_response (
3933 "get_item" ,
@@ -58,6 +52,7 @@ def test_read_post(client, mock_dynamodb):
5852 }
5953
6054
55+ @pytest .mark .parametrize ("mock_dynamodb" , [table ], indirect = True )
6156def test_create_post (client , mock_dynamodb ):
6257 post_data = {
6358 "Id" : "2" ,
@@ -74,6 +69,7 @@ def test_create_post(client, mock_dynamodb):
7469 assert response .json () == {"message" : "Post created" }
7570
7671
72+ @pytest .mark .parametrize ("mock_dynamodb" , [table ], indirect = True )
7773def test_update_post (client , mock_dynamodb ):
7874 post_data = {
7975 "Id" : "1" ,
@@ -108,6 +104,7 @@ def test_update_post(client, mock_dynamodb):
108104 assert response .json () == {"message" : "Post with id 1 updated" , "updated_attributes" : post_data }
109105
110106
107+ @pytest .mark .parametrize ("mock_dynamodb" , [table ], indirect = True )
111108def test_delete_post (client , mock_dynamodb ):
112109 mock_dynamodb .add_response (
113110 "delete_item" ,
0 commit comments