34
34
)
35
35
36
36
37
- # Generic doesn't need a more descriptive name
38
- # pylint: disable=invalid-name
39
- T = TypeVar ('T' , bound = ModelData )
40
-
41
-
42
- def setupAsync (query_result : List [T ]) -> Tuple [AsyncModel [T ], AsyncClient ]:
37
+ def setupAsync (
38
+ query_result : List [ModelData ]
39
+ ) -> Tuple [AsyncModel [ModelData ], AsyncClient ]:
43
40
"""Setup helper that returns instances of both a Model & a Client.
44
41
45
42
Mocks the execute_and_return method on the Client instance to skip
@@ -60,12 +57,14 @@ def setupAsync(query_result: List[T]) -> Tuple[AsyncModel[T], AsyncClient]:
60
57
return_value = query_result )
61
58
62
59
# init a real model with mocked client
63
- model = AsyncModel [Any ](client , 'test' )
60
+ model = AsyncModel [Any ](client , 'test' , ModelData )
64
61
65
62
return model , client
66
63
67
64
68
- def setupSync (query_result : List [T ]) -> Tuple [SyncModel [T ], SyncClient ]:
65
+ def setupSync (
66
+ query_result : List [ModelData ]
67
+ ) -> Tuple [SyncModel [ModelData ], SyncClient ]:
69
68
"""Setup helper that returns instances of both a Model & a Client.
70
69
71
70
Mocks the execute_and_return method on the Client instance to skip
@@ -86,7 +85,7 @@ def setupSync(query_result: List[T]) -> Tuple[SyncModel[T], SyncClient]:
86
85
return_value = query_result )
87
86
88
87
# init a real model with mocked client
89
- model = SyncModel [Any ](client , 'test' )
88
+ model = SyncModel [ModelData ](client , 'test' , ModelData )
90
89
91
90
return model , client
92
91
@@ -100,8 +99,8 @@ async def test_it_correctly_builds_query_with_given_id(self) -> None:
100
99
async_model , async_client = setupAsync ([item ])
101
100
sync_model , sync_client = setupSync ([item ])
102
101
103
- await async_model .read .one_by_id (str ( item .id ) )
104
- sync_model .read .one_by_id (str ( item .id ) )
102
+ await async_model .read .one_by_id (item .id )
103
+ sync_model .read .one_by_id (item .id )
105
104
106
105
async_query_composed = cast (
107
106
helpers .AsyncMock , async_client .execute_and_return ).call_args [0 ][0 ]
@@ -124,8 +123,8 @@ async def test_it_returns_a_single_result(self) -> None:
124
123
item = ModelData (id = uuid4 ())
125
124
async_model , _ = setupAsync ([item ])
126
125
sync_model , _ = setupSync ([item ])
127
- results = [await async_model .read .one_by_id (str ( item .id ) ),
128
- sync_model .read .one_by_id (str ( item .id ) )]
126
+ results = [await async_model .read .one_by_id (item .id ),
127
+ sync_model .read .one_by_id (item .id )]
129
128
130
129
for result in results :
131
130
with self .subTest ():
@@ -139,11 +138,11 @@ async def test_it_raises_exception_if_more_than_one_result(self) -> None:
139
138
140
139
with self .subTest ():
141
140
with self .assertRaises (UnexpectedMultipleResults ):
142
- await async_model .read .one_by_id (str ( item .id ) )
141
+ await async_model .read .one_by_id (item .id )
143
142
144
143
with self .subTest ():
145
144
with self .assertRaises (UnexpectedMultipleResults ):
146
- sync_model .read .one_by_id (str ( item .id ) )
145
+ sync_model .read .one_by_id (item .id )
147
146
148
147
@ helpers .async_test
149
148
async def test_it_raises_exception_if_no_result_to_return (self ) -> None :
@@ -265,8 +264,8 @@ async def test_it_returns_the_new_record(self) -> None:
265
264
sync_model , _ = setupSync ([updated ])
266
265
267
266
results = [
268
- await async_model .update .one_by_id (str ( item .id ) , {'b' : 'c' }),
269
- sync_model .update .one_by_id (str ( item .id ) , {'b' : 'c' })
267
+ await async_model .update .one_by_id (item .id , {'b' : 'c' }),
268
+ sync_model .update .one_by_id (item .id , {'b' : 'c' })
270
269
]
271
270
272
271
for result in results :
0 commit comments