@@ -369,6 +369,21 @@ def test_execute_timeout(self, mock_hook):
369
369
task .execute (mock .MagicMock )
370
370
mock_hook .return_value .list .assert_called_once_with (TEST_BUCKET , prefix = TEST_PREFIX )
371
371
372
+ @mock .patch ("airflow.providers.google.cloud.sensors.gcs.GCSHook" )
373
+ @mock .patch ("airflow.providers.google.cloud.sensors.gcs.GCSObjectsWithPrefixExistenceSensor.defer" )
374
+ def test_gcs_object_prefix_existence_sensor_finish_before_deferred (self , mock_defer , mock_hook ):
375
+ task = GCSObjectsWithPrefixExistenceSensor (
376
+ task_id = "task-id" ,
377
+ bucket = TEST_BUCKET ,
378
+ prefix = TEST_PREFIX ,
379
+ google_cloud_conn_id = TEST_GCP_CONN_ID ,
380
+ impersonation_chain = TEST_IMPERSONATION_CHAIN ,
381
+ deferrable = True ,
382
+ )
383
+ mock_hook .return_value .list .return_value = True
384
+ task .execute (mock .MagicMock ())
385
+ assert not mock_defer .called
386
+
372
387
373
388
class TestGCSObjectsWithPrefixExistenceSensorAsync :
374
389
OPERATOR = GCSObjectsWithPrefixExistenceSensor (
@@ -379,14 +394,15 @@ class TestGCSObjectsWithPrefixExistenceSensorAsync:
379
394
deferrable = True ,
380
395
)
381
396
382
- def test_gcs_object_with_prefix_existence_sensor_async (self , context ):
397
+ @mock .patch ("airflow.providers.google.cloud.sensors.gcs.GCSHook" )
398
+ def test_gcs_object_with_prefix_existence_sensor_async (self , mock_hook ):
383
399
"""
384
400
Asserts that a task is deferred and a GCSPrefixBlobTrigger will be fired
385
401
when the GCSObjectsWithPrefixExistenceSensorAsync is executed.
386
402
"""
387
-
403
+ mock_hook . return_value . list . return_value = False
388
404
with pytest .raises (TaskDeferred ) as exc :
389
- self .OPERATOR .execute (context )
405
+ self .OPERATOR .execute (mock . MagicMock () )
390
406
assert isinstance (exc .value .trigger , GCSPrefixBlobTrigger ), "Trigger is not a GCSPrefixBlobTrigger"
391
407
392
408
def test_gcs_object_with_prefix_existence_sensor_async_execute_failure (self , context ):
0 commit comments