1717from __future__ import annotations
1818
1919import json
20+ from datetime import datetime
2021
2122import pytest
2223
3132class TestMSGraphSensor (Base ):
3233 def test_execute (self ):
3334 status = load_json ("resources" , "status.json" )
34- response = mock_json_response (200 , status )
35+ response = mock_json_response (200 , * status )
3536
3637 with self .patch_hook_and_request_adapter (response ):
3738 sensor = MSGraphSensor (
@@ -40,6 +41,7 @@ def test_execute(self):
4041 url = "myorg/admin/workspaces/scanStatus/{scanId}" ,
4142 path_parameters = {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" },
4243 result_processor = lambda context , result : result ["id" ],
44+ retry_delay = 5 ,
4345 timeout = 350.0 ,
4446 )
4547
@@ -48,16 +50,22 @@ def test_execute(self):
4850 assert sensor .path_parameters == {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" }
4951 assert isinstance (results , str )
5052 assert results == "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef"
51- assert len (events ) == 1
53+ assert len (events ) == 3
5254 assert isinstance (events [0 ], TriggerEvent )
5355 assert events [0 ].payload ["status" ] == "success"
5456 assert events [0 ].payload ["type" ] == "builtins.dict"
55- assert events [0 ].payload ["response" ] == json .dumps (status )
57+ assert events [0 ].payload ["response" ] == json .dumps (status [0 ])
58+ assert isinstance (events [1 ], TriggerEvent )
59+ assert isinstance (events [1 ].payload , datetime )
60+ assert isinstance (events [2 ], TriggerEvent )
61+ assert events [2 ].payload ["status" ] == "success"
62+ assert events [2 ].payload ["type" ] == "builtins.dict"
63+ assert events [2 ].payload ["response" ] == json .dumps (status [1 ])
5664
5765 @pytest .mark .skipif (not AIRFLOW_V_2_10_PLUS , reason = "Lambda parameters works in Airflow >= 2.10.0" )
5866 def test_execute_with_lambda_parameter (self ):
5967 status = load_json ("resources" , "status.json" )
60- response = mock_json_response (200 , status )
68+ response = mock_json_response (200 , * status )
6169
6270 with self .patch_hook_and_request_adapter (response ):
6371 sensor = MSGraphSensor (
@@ -66,6 +74,7 @@ def test_execute_with_lambda_parameter(self):
6674 url = "myorg/admin/workspaces/scanStatus/{scanId}" ,
6775 path_parameters = lambda context , jinja_env : {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" },
6876 result_processor = lambda context , result : result ["id" ],
77+ retry_delay = 5 ,
6978 timeout = 350.0 ,
7079 )
7180
@@ -74,11 +83,17 @@ def test_execute_with_lambda_parameter(self):
7483 assert sensor .path_parameters == {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" }
7584 assert isinstance (results , str )
7685 assert results == "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef"
77- assert len (events ) == 1
86+ assert len (events ) == 3
7887 assert isinstance (events [0 ], TriggerEvent )
7988 assert events [0 ].payload ["status" ] == "success"
8089 assert events [0 ].payload ["type" ] == "builtins.dict"
81- assert events [0 ].payload ["response" ] == json .dumps (status )
90+ assert events [0 ].payload ["response" ] == json .dumps (status [0 ])
91+ assert isinstance (events [1 ], TriggerEvent )
92+ assert isinstance (events [1 ].payload , datetime )
93+ assert isinstance (events [2 ], TriggerEvent )
94+ assert events [2 ].payload ["status" ] == "success"
95+ assert events [2 ].payload ["type" ] == "builtins.dict"
96+ assert events [2 ].payload ["response" ] == json .dumps (status [1 ])
8297
8398 def test_template_fields (self ):
8499 sensor = MSGraphSensor (
0 commit comments