Lee-W commented on code in PR #36904:
URL: https://github.com/apache/airflow/pull/36904#discussion_r1461608276


##########
tests/providers/http/sensors/test_http.py:
##########
@@ -330,3 +331,54 @@ def test_sensor(self):
             dag=self.dag,
         )
         sensor.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE, 
ignore_ti_state=True)
+
+
+class TestHttpSensorAsync:
+    @mock.patch("airflow.providers.http.sensors.http.HttpSensor.defer")
+    @mock.patch(
+        "airflow.providers.http.sensors.http.HttpSensor.poke",
+        return_value=True,
+    )
+    def test_execute_finished_before_deferred(
+        self,
+        mock_poke,
+        mock_defer,
+    ):
+        """
+        Asserts that a task is not deferred when task is already finished
+        """
+
+        task = HttpSensor(task_id="run_now", endpoint="test-endpoint", 
deferrable=True)
+
+        task.execute({})
+        assert not mock_defer.called
+
+    @mock.patch(
+        "airflow.providers.http.sensors.http.HttpSensor.poke",
+        return_value=False,
+    )
+    def test_execute_is_deferred(self, mock_poke):
+        """
+        Asserts that a task is deferred and a HttpTrigger will be fired
+        when the HttpSensor is executed in deferrable mode.
+        """
+
+        task = HttpSensor(task_id="run_now", endpoint="test-endpoint", 
deferrable=True)
+
+        with pytest.raises(TaskDeferred) as exc:
+            task.execute({})
+
+        assert isinstance(exc.value.trigger, HttpSensorTrigger), "Trigger is 
not a HttpTrigger"
+
+    @mock.patch("airflow.providers.http.sensors.http.HttpSensor.defer")
+    @mock.patch("airflow.sensors.base.BaseSensorOperator.execute")
+    def test_sensor_not_defer(self, mock_execute, mock_defer):

Review Comment:
   ```suggestion
       def test_execute_not_defer_when_response_check_is_not_none(self, 
mock_execute, mock_defer):
   ```
   
   not sure whether this test case name is too long 🤔



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@airflow.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to