Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: HttpSensorTrigger to include method when serializing #42925

Merged
merged 3 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,
}