WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 618f177

Browse files
committed
issue-58718-asset-event-operations: Completing stubbed tests for AssetEvent operations
1 parent 9023c38 commit 618f177

File tree

3 files changed

+56
-12
lines changed

3 files changed

+56
-12
lines changed

task-sdk-integration-tests/dags/test_asset_dag.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@
2525

2626
from __future__ import annotations
2727

28-
from airflow.sdk import DAG, Asset, task
28+
from airflow.sdk import DAG, Asset, AssetAlias, task
2929

3030
test_asset = Asset(uri="test://asset1", name="test_asset")
31+
test_asset_alias = AssetAlias(name="test_asset_alias")
3132

3233
with DAG(
3334
dag_id="asset_producer_dag",
@@ -36,10 +37,14 @@
3637
catchup=False,
3738
) as producer_dag:
3839

39-
@task(outlets=[test_asset])
40-
def produce_asset():
40+
@task(outlets=[test_asset, test_asset_alias])
41+
def produce_asset(**context):
4142
"""Task that produces the test asset."""
4243
print("Producing test asset")
44+
45+
# Ensure AssetAlias is associated with Asset
46+
context["outlet_events"][test_asset_alias].add(test_asset)
47+
4348
return "asset_produced"
4449

4550
produce_asset()

task-sdk-integration-tests/tests/task_sdk_tests/conftest.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,5 +737,6 @@ def asset_test_setup(docker_compose_setup, airflow_ready):
737737
additional_metadata={
738738
"name": "test_asset",
739739
"uri": "test://asset1/",
740+
"alias_name": "test_asset_alias",
740741
},
741742
)

task-sdk-integration-tests/tests/task_sdk_tests/test_asset_event_operations.py

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323

2424
from __future__ import annotations
2525

26-
import pytest
27-
2826
from airflow.sdk.api.datamodels._generated import AssetEventsResponse
2927
from task_sdk_tests import console
3028

@@ -68,25 +66,65 @@ def test_asset_event_get_not_found(sdk_client_for_assets):
6866
console.print("[green]✅ Asset event get (not found) test passed!")
6967

7068

71-
@pytest.mark.skip(reason="TODO: Implement Asset Event get_by_uri test")
7269
def test_asset_event_get_by_uri(sdk_client_for_assets, asset_test_setup):
7370
"""
7471
Test getting asset events by URI.
7572
7673
Expected: AssetEventsResponse with events
7774
Endpoint: GET /execution/asset-events/by-asset?uri={uri}
7875
"""
79-
console.print("[yellow]TODO: Implement test_asset_event_get_by_uri")
80-
raise NotImplementedError("test_asset_event_get_by_uri not implemented")
76+
console.print("[yellow]Getting asset events by URI...")
77+
78+
response = sdk_client_for_assets.asset_events.get(uri=asset_test_setup["uri"])
79+
80+
console.print(" Asset Event Get Response ".center(72, "="))
81+
console.print(f"[bright_blue]Response Type:[/] {type(response).__name__}")
82+
console.print(f"[bright_blue]Number of Events:[/] {len(response.asset_events)}")
83+
84+
assert isinstance(response, AssetEventsResponse)
85+
assert len(response.asset_events) >= 1
86+
87+
event = response.asset_events[0]
88+
89+
console.print(f"[bright_blue]First Event ID:[/] {event.id}")
90+
console.print(f"[bright_blue]First Event Asset Name:[/] {event.asset.name}")
91+
console.print(f"[bright_blue]First Event Asset URI:[/] {event.asset.uri}")
92+
console.print(f"[bright_blue]First Event Timestamp:[/] {event.timestamp}")
93+
console.print("=" * 72)
94+
95+
assert event.asset.name == asset_test_setup["name"]
96+
assert event.asset.uri == asset_test_setup["uri"]
97+
98+
console.print("[green]✅ Asset event get (URI) test passed!")
8199

82100

83-
@pytest.mark.skip(reason="TODO: Implement Asset Event get_by_alias test")
84-
def test_asset_event_get_by_alias(sdk_client_for_assets):
101+
def test_asset_event_get_by_alias(sdk_client_for_assets, asset_test_setup):
85102
"""
86103
Test getting asset events by alias name.
87104
88105
Expected: AssetEventsResponse with events
89106
Endpoint: GET /execution/asset-events/by-asset-alias?name={alias_name}
90107
"""
91-
console.print("[yellow]TODO: Implement test_asset_event_get_by_alias")
92-
raise NotImplementedError("test_asset_event_get_by_alias not implemented")
108+
console.print("[yellow]Getting asset events by alias...")
109+
110+
response = sdk_client_for_assets.asset_events.get(alias_name=asset_test_setup["alias_name"])
111+
112+
console.print(" Asset Event Get Response ".center(72, "="))
113+
console.print(f"[bright_blue]Response Type:[/] {type(response).__name__}")
114+
console.print(f"[bright_blue]Number of Events:[/] {len(response.asset_events)}")
115+
116+
assert isinstance(response, AssetEventsResponse)
117+
assert len(response.asset_events) >= 1
118+
119+
event = response.asset_events[0]
120+
121+
console.print(f"[bright_blue]First Event ID:[/] {event.id}")
122+
console.print(f"[bright_blue]First Event Asset Name:[/] {event.asset.name}")
123+
console.print(f"[bright_blue]First Event Asset URI:[/] {event.asset.uri}")
124+
console.print(f"[bright_blue]First Event Timestamp:[/] {event.timestamp}")
125+
console.print("=" * 72)
126+
127+
assert event.asset.name == asset_test_setup["name"]
128+
assert event.asset.uri == asset_test_setup["uri"]
129+
130+
console.print("[green]✅ Asset event get (alias) test passed!")

0 commit comments

Comments
 (0)