Skip to content

Commit 8168358

Browse files
authored
Add test for forced stringification (apache#55950)
1 parent ab48b2b commit 8168358

File tree

1 file changed

+17
-1
lines changed
  • airflow-core/tests/unit/api_fastapi/core_api/routes/public

1 file changed

+17
-1
lines changed

airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_xcom.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
from airflow.models.taskinstance import TaskInstance
3030
from airflow.models.xcom import XComModel
3131
from airflow.providers.standard.operators.empty import EmptyOperator
32-
from airflow.sdk import DAG
32+
from airflow.sdk import DAG, AssetAlias
3333
from airflow.sdk.bases.xcom import BaseXCom
3434
from airflow.sdk.execution_time.xcom import resolve_xcom_backend
3535
from airflow.utils.session import provide_session
@@ -194,6 +194,22 @@ def test_custom_xcom_deserialize(self, params: str, expected_value: int | str, t
194194
assert response.status_code == 200
195195
assert response.json()["value"] == expected_value
196196

197+
@pytest.mark.parametrize(
198+
"xcom_value, expected_return",
199+
[
200+
pytest.param(42, 42, id="jsonable"),
201+
pytest.param(AssetAlias("x"), "AssetAlias(name='x', group='asset')", id="nonjsonable"),
202+
pytest.param([42, AssetAlias("x")], [42, "AssetAlias(name='x', group='asset')"], id="nested"),
203+
],
204+
)
205+
def test_stringify_false(self, test_client, xcom_value, expected_return):
206+
XComModel.set(TEST_XCOM_KEY, xcom_value, dag_id=TEST_DAG_ID, task_id=TEST_TASK_ID, run_id=run_id)
207+
208+
url = f"/dags/{TEST_DAG_ID}/dagRuns/{run_id}/taskInstances/{TEST_TASK_ID}/xcomEntries/{TEST_XCOM_KEY}"
209+
response = test_client.get(url, params={"deserialize": True, "stringify": False})
210+
assert response.status_code == 200
211+
assert response.json()["value"] == expected_return
212+
197213

198214
class TestGetXComEntries(TestXComEndpoint):
199215
@pytest.fixture(autouse=True)

0 commit comments

Comments
 (0)