Skip to content

Commit

Permalink
fix: HttpSensorTrigger to include method when serializing (#42925)
Browse files Browse the repository at this point in the history
  • Loading branch information
rawwar authored Oct 11, 2024
1 parent 7202ee8 commit 0372743
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions providers/src/airflow/providers/http/triggers/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ def serialize(self) -> tuple[str, dict[str, Any]]:
{
"endpoint": self.endpoint,
"data": self.data,
"method": self.method,
"headers": self.headers,
"extra_options": self.extra_options,
"http_conn_id": self.http_conn_id,
Expand Down
33 changes: 32 additions & 1 deletion providers/tests/http/triggers/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from requests.structures import CaseInsensitiveDict
from yarl import URL

from airflow.providers.http.triggers.http import HttpTrigger
from airflow.providers.http.triggers.http import HttpSensorTrigger, HttpTrigger
from airflow.triggers.base import TriggerEvent

HTTP_PATH = "airflow.providers.http.triggers.http.{}"
Expand All @@ -56,6 +56,18 @@ def trigger():
)


@pytest.fixture
def sensor_trigger():
return HttpSensorTrigger(
http_conn_id=TEST_CONN_ID,
endpoint=TEST_ENDPOINT,
method=TEST_METHOD,
headers=TEST_HEADERS,
data=TEST_DATA,
extra_options=TEST_EXTRA_OPTIONS,
)


@pytest.fixture
def client_response():
client_response = mock.AsyncMock(ClientResponse)
Expand Down Expand Up @@ -153,3 +165,22 @@ async def test_trigger_on_post_with_data(self, mock_http_post, trigger):
assert kwargs["data"] == TEST_DATA
assert kwargs["json"] is None
assert kwargs["params"] is None


class TestHttpSensorTrigger:
def test_serialization(self, sensor_trigger):
"""
Asserts that the HttpSensorTrigger correctly serializes its arguments
and classpath.
"""
classpath, kwargs = sensor_trigger.serialize()
assert classpath == "airflow.providers.http.triggers.http.HttpSensorTrigger"
assert kwargs == {
"http_conn_id": TEST_CONN_ID,
"endpoint": TEST_ENDPOINT,
"method": TEST_METHOD,
"headers": TEST_HEADERS,
"data": TEST_DATA,
"extra_options": TEST_EXTRA_OPTIONS,
"poke_interval": 5.0,
}

0 comments on commit 0372743

Please sign in to comment.