17
17
from __future__ import annotations
18
18
19
19
import json
20
+ from datetime import datetime
20
21
21
22
import pytest
22
23
31
32
class TestMSGraphSensor (Base ):
32
33
def test_execute (self ):
33
34
status = load_json ("resources" , "status.json" )
34
- response = mock_json_response (200 , status )
35
+ response = mock_json_response (200 , * status )
35
36
36
37
with self .patch_hook_and_request_adapter (response ):
37
38
sensor = MSGraphSensor (
@@ -40,6 +41,7 @@ def test_execute(self):
40
41
url = "myorg/admin/workspaces/scanStatus/{scanId}" ,
41
42
path_parameters = {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" },
42
43
result_processor = lambda context , result : result ["id" ],
44
+ retry_delay = 5 ,
43
45
timeout = 350.0 ,
44
46
)
45
47
@@ -48,16 +50,22 @@ def test_execute(self):
48
50
assert sensor .path_parameters == {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" }
49
51
assert isinstance (results , str )
50
52
assert results == "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef"
51
- assert len (events ) == 1
53
+ assert len (events ) == 3
52
54
assert isinstance (events [0 ], TriggerEvent )
53
55
assert events [0 ].payload ["status" ] == "success"
54
56
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 ])
56
64
57
65
@pytest .mark .skipif (not AIRFLOW_V_2_10_PLUS , reason = "Lambda parameters works in Airflow >= 2.10.0" )
58
66
def test_execute_with_lambda_parameter (self ):
59
67
status = load_json ("resources" , "status.json" )
60
- response = mock_json_response (200 , status )
68
+ response = mock_json_response (200 , * status )
61
69
62
70
with self .patch_hook_and_request_adapter (response ):
63
71
sensor = MSGraphSensor (
@@ -66,6 +74,7 @@ def test_execute_with_lambda_parameter(self):
66
74
url = "myorg/admin/workspaces/scanStatus/{scanId}" ,
67
75
path_parameters = lambda context , jinja_env : {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" },
68
76
result_processor = lambda context , result : result ["id" ],
77
+ retry_delay = 5 ,
69
78
timeout = 350.0 ,
70
79
)
71
80
@@ -74,11 +83,17 @@ def test_execute_with_lambda_parameter(self):
74
83
assert sensor .path_parameters == {"scanId" : "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef" }
75
84
assert isinstance (results , str )
76
85
assert results == "0a1b1bf3-37de-48f7-9863-ed4cda97a9ef"
77
- assert len (events ) == 1
86
+ assert len (events ) == 3
78
87
assert isinstance (events [0 ], TriggerEvent )
79
88
assert events [0 ].payload ["status" ] == "success"
80
89
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 ])
82
97
83
98
def test_template_fields (self ):
84
99
sensor = MSGraphSensor (
0 commit comments