|
| 1 | +import json |
| 2 | +from pathlib import Path |
| 3 | + |
1 | 4 | import dagster_airlift.core as dg_airlift_core
|
2 | 5 | import pytest
|
| 6 | +import yaml |
| 7 | +from click.testing import CliRunner |
| 8 | +from dagster.components.cli import cli |
3 | 9 | from dagster_airlift.core.components.airflow_instance.component import AirflowInstanceComponent
|
4 | 10 | from dagster_airlift.test import make_instance
|
5 | 11 | from dagster_airlift.test.test_utils import asset_spec
|
6 |
| -from dagster_tests.components_tests.utils import build_component_defs_for_test |
| 12 | +from dagster_tests.components_tests.utils import ( |
| 13 | + build_component_defs_for_test, |
| 14 | + temp_code_location_bar, |
| 15 | +) |
7 | 16 |
|
8 | 17 |
|
9 | 18 | @pytest.fixture
|
@@ -65,3 +74,56 @@ def test_load_dags_basic(component_for_test: type[AirflowInstanceComponent]) ->
|
65 | 74 | assert keyed_spec.metadata["foo"] == "bar"
|
66 | 75 |
|
67 | 76 | assert len(defs.jobs) == 3 # monitoring job + 2 dag jobs.
|
| 77 | + |
| 78 | + |
| 79 | +def _scaffold_airlift(scaffold_format: str): |
| 80 | + runner = CliRunner() |
| 81 | + result = runner.invoke( |
| 82 | + cli, |
| 83 | + [ |
| 84 | + "scaffold", |
| 85 | + "object", |
| 86 | + "dagster_airlift.core.components.airflow_instance.component.AirflowInstanceComponent", |
| 87 | + "bar/components/qux", |
| 88 | + "--json-params", |
| 89 | + json.dumps({"name": "qux", "auth_type": "basic_auth"}), |
| 90 | + "--scaffold-format", |
| 91 | + scaffold_format, |
| 92 | + ], |
| 93 | + ) |
| 94 | + assert result.exit_code == 0 |
| 95 | + |
| 96 | + |
| 97 | +def test_scaffold_airlift_yaml(): |
| 98 | + with temp_code_location_bar(): |
| 99 | + _scaffold_airlift("yaml") |
| 100 | + assert Path("bar/components/qux/component.yaml").exists() |
| 101 | + with open("bar/components/qux/component.yaml") as f: |
| 102 | + assert yaml.safe_load(f) == { |
| 103 | + "type": "dagster_airlift.core.components.airflow_instance.component.AirflowInstanceComponent", |
| 104 | + "attributes": { |
| 105 | + "name": "qux", |
| 106 | + "auth": { |
| 107 | + "type": "basic_auth", |
| 108 | + "webserver_url": '{{ env("AIRFLOW_WEBSERVER_URL") }}', |
| 109 | + "username": '{{ env("AIRFLOW_USERNAME") }}', |
| 110 | + "password": '{{ env("AIRFLOW_PASSWORD") }}', |
| 111 | + }, |
| 112 | + }, |
| 113 | + } |
| 114 | + |
| 115 | + |
| 116 | +def test_scaffold_airlift_python(): |
| 117 | + with temp_code_location_bar(): |
| 118 | + _scaffold_airlift("python") |
| 119 | + assert Path("bar/components/qux/component.py").exists() |
| 120 | + with open("bar/components/qux/component.py") as f: |
| 121 | + file_contents = f.read() |
| 122 | + assert file_contents == ( |
| 123 | + """from dagster.components import component, ComponentLoadContext |
| 124 | +from dagster_airlift.core.components.airflow_instance.component import AirflowInstanceComponent |
| 125 | +
|
| 126 | +@component |
| 127 | +def load(context: ComponentLoadContext) -> AirflowInstanceComponent: ... |
| 128 | +""" |
| 129 | + ) |
0 commit comments