11import datetime
22
33import pytest
4+ from gcloud .aio .taskqueue import PushQueue
45
56
67@pytest .mark .asyncio
7- async def test_task_lifecycle_in_push_queue (push_queue ):
8+ async def test_task_lifecycle_in_push_queue (
9+ project , creds , push_queue_name , push_queue_location
10+ ):
811 # Set to run in the future, giving us enough time to test all
912 # functionalities before the task gets dispatched automatically.
1013 schedule_time = (datetime .datetime .now (datetime .timezone .utc )
@@ -20,22 +23,26 @@ async def test_task_lifecycle_in_push_queue(push_queue):
2023 },
2124 }
2225
23- # CREATE
24- created = await push_queue .create (task )
25- assert created
26-
27- try :
28- # GET
29- assert created == await push_queue .get (created ['name' ], full = True )
30-
31- # LIST
32- listed = await push_queue .list (full = True )
33- assert listed .get ('tasks' )
34- assert created in listed ['tasks' ]
35-
36- # RUN
37- run = await push_queue .run (created ['name' ], full = True )
38- assert all (item in run .items () for item in created .items ())
39- finally :
40- # DELETE
41- assert not await push_queue .delete (created ['name' ])
26+ async with PushQueue (
27+ project , push_queue_name , service_file = creds ,
28+ location = push_queue_location ,
29+ ) as push_queue :
30+ # CREATE
31+ created = await push_queue .create (task )
32+ assert created
33+
34+ try :
35+ # GET
36+ assert created == await push_queue .get (created ['name' ], full = True )
37+
38+ # LIST
39+ listed = await push_queue .list (full = True )
40+ assert listed .get ('tasks' )
41+ assert created in listed ['tasks' ]
42+
43+ # RUN
44+ run = await push_queue .run (created ['name' ], full = True )
45+ assert all (item in run .items () for item in created .items ())
46+ finally :
47+ # DELETE
48+ assert not await push_queue .delete (created ['name' ])
0 commit comments