Skip to content

Commit ac39ba4

Browse files
committed
test
1 parent 823a6f0 commit ac39ba4

File tree

2 files changed

+84
-1
lines changed

2 files changed

+84
-1
lines changed

tests/api_fastapi/execution_api/routes/test_task_instances.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,39 @@ def test_ti_run_state_conflict_if_not_queued(
136136

137137
assert session.scalar(select(TaskInstance.state).where(TaskInstance.id == ti.id)) == initial_ti_state
138138

139+
def test_ti_run_failed_with_extra(self, client, session, create_task_instance, time_machine):
140+
"""
141+
Test that a 422 error is returned when extra fields are included in the payload.
142+
"""
143+
instant_str = "2024-12-19T00:00:00Z"
144+
instant = timezone.parse(instant_str)
145+
time_machine.move_to(instant, tick=False)
146+
147+
ti = create_task_instance(
148+
task_id="test_ti_run_failed_with_extra",
149+
state=State.QUEUED,
150+
session=session,
151+
start_date=instant,
152+
)
153+
154+
session.commit()
155+
156+
response = client.patch(
157+
f"/execution/task-instances/{ti.id}/run",
158+
json={
159+
"state": "running",
160+
"hostname": "random-hostname",
161+
"unixname": "random-unixname",
162+
"pid": 100,
163+
"start_date": instant_str,
164+
"foo": "bar",
165+
},
166+
)
167+
168+
assert response.status_code == 422
169+
assert response.json()["detail"][0]["type"] == "extra_forbidden"
170+
assert response.json()["detail"][0]["msg"] == "Extra inputs are not permitted"
171+
139172

140173
class TestTIUpdateState:
141174
def setup_method(self):
@@ -340,6 +373,27 @@ def test_ti_update_state_to_reschedule(self, client, session, create_task_instan
340373
assert trs[0].map_index == -1
341374
assert trs[0].duration == 129600
342375

376+
def test_ti_update_state_failed_with_extra(self, client, session, create_task_instance, time_machine):
377+
"""
378+
Test that a 422 error is returned when extra fields are included in the payload.
379+
"""
380+
ti = create_task_instance(
381+
task_id="test_ti_update_state_failed_with_extra",
382+
state=State.RUNNING,
383+
session=session,
384+
start_date=DEFAULT_START_DATE,
385+
)
386+
387+
session.commit()
388+
389+
response = client.patch(
390+
f"/execution/task-instances/{ti.id}/state", json={"state": "scheduled", "foo": "bar"}
391+
)
392+
393+
assert response.status_code == 422
394+
assert response.json()["detail"][0]["type"] == "extra_forbidden"
395+
assert response.json()["detail"][0]["msg"] == "Extra inputs are not permitted"
396+
343397

344398
class TestTIHealthEndpoint:
345399
def setup_method(self):
@@ -536,6 +590,35 @@ def test_ti_update_state_to_failed_table_check(self, client, session, create_tas
536590
assert ti.next_kwargs is None
537591
assert ti.duration == 3600.00
538592

593+
def test_ti_heartbeat_with_extra(
594+
self,
595+
client,
596+
session,
597+
create_task_instance,
598+
time_machine,
599+
):
600+
"""
601+
Test that a 422 error is returned when extra fields are included in the payload.
602+
"""
603+
ti = create_task_instance(
604+
task_id="test_ti_heartbeat_when_task_not_running",
605+
state=State.RUNNING,
606+
hostname="random-hostname",
607+
pid=1547,
608+
session=session,
609+
)
610+
session.commit()
611+
task_instance_id = ti.id
612+
613+
response = client.put(
614+
f"/execution/task-instances/{task_instance_id}/heartbeat",
615+
json={"hostname": "random-hostname", "pid": 1547, "foo": "bar"},
616+
)
617+
618+
assert response.status_code == 422
619+
assert response.json()["detail"][0]["type"] == "extra_forbidden"
620+
assert response.json()["detail"][0]["msg"] == "Extra inputs are not permitted"
621+
539622

540623
class TestTIPutRTIF:
541624
def setup_method(self):

tests/api_fastapi/execution_api/routes/test_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def test_variable_get_from_db(self, client, session):
5454
{"AIRFLOW_VAR_KEY1": "VALUE"},
5555
)
5656
def test_variable_get_from_env_var(self, client, session):
57-
response = client.get("/execution/variables/key1", params={"foo": "bar"})
57+
response = client.get("/execution/variables/key1")
5858

5959
assert response.status_code == 200
6060
assert response.json() == {"key": "key1", "value": "VALUE"}

0 commit comments

Comments
 (0)