File tree 4 files changed +39
-1
lines changed
airflow/providers/google/cloud
tests/providers/google/cloud
4 files changed +39
-1
lines changed Original file line number Diff line number Diff line change @@ -84,7 +84,7 @@ def execute(self, context: "Context") -> str:
84
84
85
85
self .materialization_id = resp .materialization_id
86
86
87
- if self .materialization_id is None :
87
+ if not self .materialization_id :
88
88
raise AirflowException (
89
89
f'No `materialization_id` was returned for model: { self .model } , view: { self .view } .'
90
90
)
Original file line number Diff line number Diff line change @@ -53,6 +53,11 @@ def poke(self, context: "Context") -> bool:
53
53
54
54
self .hook = LookerHook (looker_conn_id = self .looker_conn_id )
55
55
56
+ if not self .materialization_id :
57
+ raise AirflowException (
58
+ f'Invalid `materialization_id`.'
59
+ )
60
+
56
61
# materialization_id is templated var pulling output from start task
57
62
status_dict = self .hook .pdt_build_status (materialization_id = self .materialization_id )
58
63
status = status_dict ['status' ]
Original file line number Diff line number Diff line change 19
19
from unittest import mock
20
20
from unittest .mock import MagicMock
21
21
22
+ import pytest
23
+
24
+ from airflow .exceptions import AirflowException
22
25
from airflow .models import DAG , DagBag
23
26
from airflow .providers .google .cloud .operators .looker import LookerStartPdtBuildOperator
24
27
from airflow .utils .timezone import datetime
@@ -146,3 +149,21 @@ def test_on_kill(self, mock_hook):
146
149
task .cancel_on_kill = True
147
150
task .on_kill ()
148
151
mock_hook .return_value .stop_pdt_build .assert_called_once_with (materialization_id = TEST_JOB_ID )
152
+
153
+ @mock .patch (OPERATOR_PATH .format ("LookerHook" ))
154
+ def test_materialization_id_returned_as_empty_str (self , mock_hook ):
155
+ # mock return vals from hook
156
+ mock_hook .return_value .start_pdt_build .return_value .materialization_id = ""
157
+ mock_hook .return_value .wait_for_job .return_value = None
158
+
159
+ # run task in mock context (asynchronous=False)
160
+ task = LookerStartPdtBuildOperator (
161
+ task_id = TASK_ID ,
162
+ looker_conn_id = LOOKER_CONN_ID ,
163
+ model = MODEL ,
164
+ view = VIEW ,
165
+ )
166
+
167
+ # check AirflowException is raised
168
+ with pytest .raises (AirflowException , match = "No `materialization_id` was returned" ):
169
+ task .execute (context = self .mock_context )
Original file line number Diff line number Diff line change @@ -105,3 +105,15 @@ def test_cancelled(self, mock_hook):
105
105
106
106
# assert hook.pdt_build_status called once
107
107
mock_hook .return_value .pdt_build_status .assert_called_once_with (materialization_id = TEST_JOB_ID )
108
+
109
+ def test_empty_materialization_id (self ):
110
+
111
+ # run task in mock context
112
+ sensor = LookerCheckPdtBuildSensor (
113
+ task_id = TASK_ID ,
114
+ looker_conn_id = LOOKER_CONN_ID ,
115
+ materialization_id = "" ,
116
+ )
117
+
118
+ with pytest .raises (AirflowException , match = "Invalid `materialization_id`" ):
119
+ sensor .poke (context = {})
You can’t perform that action at this time.
0 commit comments