@@ -40,8 +40,7 @@ async def make_cookie(
40
40
}
41
41
value = json .dumps (session_data )
42
42
key = uuid .uuid4 ().hex
43
- with await redis as conn :
44
- await conn .set ('AIOHTTP_SESSION_' + key , value )
43
+ await redis .set ('AIOHTTP_SESSION_' + key , value )
45
44
# Ignoring type until aiohttp#4252 is released
46
45
client .session .cookie_jar .update_cookies (
47
46
{'AIOHTTP_SESSION' : key } # type: ignore
@@ -53,8 +52,7 @@ async def make_cookie_with_bad_value(
53
52
redis : aioredis .commands .Redis
54
53
) -> None :
55
54
key = uuid .uuid4 ().hex
56
- with await redis as conn :
57
- await conn .set ('AIOHTTP_SESSION_' + key , '' )
55
+ await redis .set ('AIOHTTP_SESSION_' + key , '' )
58
56
# Ignoring type until aiohttp#4252 is released
59
57
client .session .cookie_jar .update_cookies (
60
58
{'AIOHTTP_SESSION' : key } # type: ignore
@@ -67,11 +65,10 @@ async def load_cookie(
67
65
) -> Any :
68
66
cookies = client .session .cookie_jar .filter_cookies (client .make_url ('/' ))
69
67
key = cookies ['AIOHTTP_SESSION' ]
70
- with await redis as conn :
71
- encoded = await conn .get ('AIOHTTP_SESSION_' + key .value )
72
- s = encoded .decode ('utf-8' )
73
- value = json .loads (s )
74
- return value
68
+ encoded = await redis .get ('AIOHTTP_SESSION_' + key .value )
69
+ s = encoded .decode ('utf-8' )
70
+ value = json .loads (s )
71
+ return value
75
72
76
73
77
74
async def test_create_new_session (
@@ -207,9 +204,8 @@ async def handler(request: web.Request) -> web.StreamResponse:
207
204
morsel = resp .cookies ['AIOHTTP_SESSION' ]
208
205
assert morsel ['httponly' ]
209
206
assert morsel ['path' ] == '/'
210
- with await redis as conn :
211
- exists = await conn .exists ('AIOHTTP_SESSION_' + morsel .value )
212
- assert exists
207
+ exists = await redis .exists ('AIOHTTP_SESSION_' + morsel .value )
208
+ assert exists
213
209
214
210
215
211
async def test_set_ttl_on_session_saving (
@@ -228,8 +224,7 @@ async def handler(request: web.Request) -> web.StreamResponse:
228
224
229
225
key = resp .cookies ['AIOHTTP_SESSION' ].value
230
226
231
- with await redis as conn :
232
- ttl = await conn .ttl ('AIOHTTP_SESSION_' + key )
227
+ ttl = await redis .ttl ('AIOHTTP_SESSION_' + key )
233
228
234
229
assert ttl > 9
235
230
assert ttl <= 10
@@ -252,8 +247,7 @@ async def handler(request: web.Request) -> web.StreamResponse:
252
247
253
248
key = resp .cookies ['AIOHTTP_SESSION' ].value
254
249
255
- with await redis as conn :
256
- ttl = await conn .ttl ('AIOHTTP_SESSION_' + key )
250
+ ttl = await redis .ttl ('AIOHTTP_SESSION_' + key )
257
251
258
252
assert ttl > 9
259
253
assert ttl <= 10
@@ -341,9 +335,8 @@ async def test_redis_from_create_pool(
341
335
async def handler (request : web .Request ) -> web .StreamResponse :
342
336
pass
343
337
344
- redis = await aioredis .create_pool (** redis_params )
345
- with pytest .warns (DeprecationWarning ):
346
- create_app (handler = handler , redis = redis )
338
+ redis = await aioredis .create_redis (** redis_params )
339
+ create_app (handler = handler , redis = redis )
347
340
348
341
349
342
async def test_not_redis_provided_to_storage () -> None :
0 commit comments