2222)
2323from sqlalchemy import literal_column
2424from sqlalchemy .engine .row import Row
25- from sqlalchemy .ext .asyncio import AsyncEngine
25+ from sqlalchemy .ext .asyncio import AsyncConnection , AsyncEngine
2626
2727
2828async def test_get_raises_if_not_found (
29- faker : Faker , connection : aiopg .sa .connection .SAConnection
29+ asyncpg_engine : AsyncEngine ,
30+ faker : Faker ,
3031):
3132 with pytest .raises (GroupExtraPropertiesNotFoundError ):
32- await GroupExtraPropertiesRepo .get (
33- connection , gid = faker .pyint (min_value = 1 ), product_name = faker .pystr ()
33+ await GroupExtraPropertiesRepo .get_v2 (
34+ asyncpg_engine ,
35+ gid = faker .pyint (min_value = 1 ),
36+ product_name = faker .pystr (),
3437 )
3538
3639
@@ -81,28 +84,6 @@ async def _creator(
8184 )
8285
8386
84- async def test_get (
85- connection : aiopg .sa .connection .SAConnection ,
86- registered_user : RowProxy ,
87- product_name : str ,
88- create_fake_product : Callable [[str ], Awaitable [Row ]],
89- create_fake_group_extra_properties : Callable [..., Awaitable [GroupExtraProperties ]],
90- ):
91- with pytest .raises (GroupExtraPropertiesNotFoundError ):
92- await GroupExtraPropertiesRepo .get (
93- connection , gid = registered_user .primary_gid , product_name = product_name
94- )
95-
96- await create_fake_product (product_name )
97- created_extra_properties = await create_fake_group_extra_properties (
98- registered_user .primary_gid , product_name
99- )
100- received_extra_properties = await GroupExtraPropertiesRepo .get (
101- connection , gid = registered_user .primary_gid , product_name = product_name
102- )
103- assert created_extra_properties == received_extra_properties
104-
105-
10687async def test_get_v2 (
10788 asyncpg_engine : AsyncEngine ,
10889 registered_user : RowProxy ,
@@ -135,27 +116,30 @@ async def everyone_group_id(connection: aiopg.sa.connection.SAConnection) -> int
135116
136117
137118async def test_get_aggregated_properties_for_user_with_no_entries_raises (
138- connection : aiopg .sa .connection .SAConnection ,
119+ connection_factory : aiopg .sa .connection .SAConnection | AsyncConnection ,
139120 product_name : str ,
140121 registered_user : RowProxy ,
141122):
142123 with pytest .raises (GroupExtraPropertiesNotFoundError ):
143124 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
144- connection , user_id = registered_user .id , product_name = product_name
125+ connection_factory , user_id = registered_user .id , product_name = product_name
145126 )
146127
147128
148129async def _add_user_to_group (
149- connection : aiopg .sa .connection .SAConnection , * , user_id : int , group_id : int
130+ connection : aiopg .sa .connection .SAConnection | AsyncConnection ,
131+ * ,
132+ user_id : int ,
133+ group_id : int ,
150134) -> None :
151- result = await connection .execute (
135+ await connection .execute (
152136 sqlalchemy .insert (user_to_groups ).values (uid = user_id , gid = group_id )
153137 )
154- assert result .rowcount == 1
155138
156139
157140async def test_get_aggregated_properties_for_user_returns_properties_in_expected_priority (
158141 connection : aiopg .sa .connection .SAConnection ,
142+ connection_factory : aiopg .sa .connection .SAConnection | AsyncConnection ,
159143 product_name : str ,
160144 registered_user : RowProxy ,
161145 create_fake_product : Callable [[str ], Awaitable [Row ]],
@@ -177,21 +161,21 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
177161 # this should return the everyone group properties
178162 aggregated_group_properties = (
179163 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
180- connection , user_id = registered_user .id , product_name = product_name
164+ connection_factory , user_id = registered_user .id , product_name = product_name
181165 )
182166 )
183167 assert aggregated_group_properties == everyone_group_extra_properties
184168
185169 # let's add the user in these groups
186170 for group in created_groups :
187171 await _add_user_to_group (
188- connection , user_id = registered_user .id , group_id = group .gid
172+ connection_factory , user_id = registered_user .id , group_id = group .gid
189173 )
190174
191175 # this changes nothing
192176 aggregated_group_properties = (
193177 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
194- connection , user_id = registered_user .id , product_name = product_name
178+ connection_factory , user_id = registered_user .id , product_name = product_name
195179 )
196180 )
197181 assert aggregated_group_properties == everyone_group_extra_properties
@@ -205,7 +189,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
205189 # this returns the last properties created
206190 aggregated_group_properties = (
207191 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
208- connection , user_id = registered_user .id , product_name = product_name
192+ connection_factory , user_id = registered_user .id , product_name = product_name
209193 )
210194 )
211195 assert aggregated_group_properties != everyone_group_extra_properties
@@ -218,14 +202,15 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
218202 # this now returns the primary properties
219203 aggregated_group_properties = (
220204 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
221- connection , user_id = registered_user .id , product_name = product_name
205+ connection_factory , user_id = registered_user .id , product_name = product_name
222206 )
223207 )
224208 assert aggregated_group_properties == personal_group_extra_properties
225209
226210
227211async def test_get_aggregated_properties_for_user_returns_properties_in_expected_priority_without_everyone_group (
228212 connection : aiopg .sa .connection .SAConnection ,
213+ connection_factory : aiopg .sa .connection .SAConnection | AsyncConnection ,
229214 product_name : str ,
230215 registered_user : RowProxy ,
231216 create_fake_product : Callable [[str ], Awaitable [Row ]],
@@ -241,7 +226,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
241226 # let's add the user in these groups
242227 for group in created_groups :
243228 await _add_user_to_group (
244- connection , user_id = registered_user .id , group_id = group .gid
229+ connection_factory , user_id = registered_user .id , group_id = group .gid
245230 )
246231
247232 # now create some extra properties
@@ -253,7 +238,7 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
253238 # this returns the last properties created
254239 aggregated_group_properties = (
255240 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
256- connection , user_id = registered_user .id , product_name = product_name
241+ connection_factory , user_id = registered_user .id , product_name = product_name
257242 )
258243 )
259244 assert aggregated_group_properties == standard_group_extra_properties [0 ]
@@ -265,14 +250,15 @@ async def test_get_aggregated_properties_for_user_returns_properties_in_expected
265250 # this now returns the primary properties
266251 aggregated_group_properties = (
267252 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
268- connection , user_id = registered_user .id , product_name = product_name
253+ connection_factory , user_id = registered_user .id , product_name = product_name
269254 )
270255 )
271256 assert aggregated_group_properties == personal_group_extra_properties
272257
273258
274259async def test_get_aggregated_properties_for_user_returns_property_values_as_truthy_if_one_of_them_is (
275260 connection : aiopg .sa .connection .SAConnection ,
261+ connection_factory : aiopg .sa .connection .SAConnection | AsyncConnection ,
276262 product_name : str ,
277263 registered_user : RowProxy ,
278264 create_fake_product : Callable [[str ], Awaitable [Row ]],
@@ -294,7 +280,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
294280 # this should return the everyone group properties
295281 aggregated_group_properties = (
296282 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
297- connection , user_id = registered_user .id , product_name = product_name
283+ connection_factory , user_id = registered_user .id , product_name = product_name
298284 )
299285 )
300286 assert aggregated_group_properties == everyone_group_extra_properties
@@ -310,13 +296,13 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
310296 use_on_demand_clusters = False ,
311297 )
312298 await _add_user_to_group (
313- connection , user_id = registered_user .id , group_id = group .gid
299+ connection_factory , user_id = registered_user .id , group_id = group .gid
314300 )
315301
316302 # now we still should not have any of these value Truthy
317303 aggregated_group_properties = (
318304 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
319- connection , user_id = registered_user .id , product_name = product_name
305+ connection_factory , user_id = registered_user .id , product_name = product_name
320306 )
321307 )
322308 assert aggregated_group_properties .internet_access is False
@@ -335,7 +321,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
335321 # now we should have internet access
336322 aggregated_group_properties = (
337323 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
338- connection , user_id = registered_user .id , product_name = product_name
324+ connection_factory , user_id = registered_user .id , product_name = product_name
339325 )
340326 )
341327 assert aggregated_group_properties .internet_access is True
@@ -354,7 +340,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
354340 # now we should have internet access and service override
355341 aggregated_group_properties = (
356342 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
357- connection , user_id = registered_user .id , product_name = product_name
343+ connection_factory , user_id = registered_user .id , product_name = product_name
358344 )
359345 )
360346 assert aggregated_group_properties .internet_access is True
@@ -373,7 +359,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
373359
374360 aggregated_group_properties = (
375361 await GroupExtraPropertiesRepo .get_aggregated_properties_for_user (
376- connection , user_id = registered_user .id , product_name = product_name
362+ connection_factory , user_id = registered_user .id , product_name = product_name
377363 )
378364 )
379365 assert aggregated_group_properties .internet_access is False
@@ -384,6 +370,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
384370async def test_get_aggregated_properties_for_user_returns_property_values_as_truthy_if_one_of_them_is_v2 (
385371 asyncpg_engine : AsyncEngine ,
386372 connection : aiopg .sa .connection .SAConnection ,
373+ connection_factory : aiopg .sa .connection .SAConnection | AsyncConnection ,
387374 product_name : str ,
388375 registered_user : RowProxy ,
389376 create_fake_product : Callable [[str ], Awaitable [Row ]],
@@ -421,7 +408,7 @@ async def test_get_aggregated_properties_for_user_returns_property_values_as_tru
421408 use_on_demand_clusters = False ,
422409 )
423410 await _add_user_to_group (
424- connection , user_id = registered_user .id , group_id = group .gid
411+ connection_factory , user_id = registered_user .id , group_id = group .gid
425412 )
426413
427414 # now we still should not have any of these value Truthy
0 commit comments