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

Add missing DbtSourceGcpCloudRunJobOperator in module cosmos.operators.gcp_cloud_run_job #1290

Merged
merged 9 commits into from
Nov 11, 2024
10 changes: 10 additions & 0 deletions cosmos/operators/gcp_cloud_run_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
DbtRunOperationMixin,
DbtSeedMixin,
DbtSnapshotMixin,
DbtSourceMixin,
DbtTestMixin,
)

Expand Down Expand Up @@ -135,6 +136,15 @@ def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)


class DbtSourceGcpCloudRunJobOperator(DbtSourceMixin, DbtGcpCloudRunJobBaseOperator):
"""
Executes a dbt core source freshness command.
"""

def __init__(self, *args: Any, **kwargs: Any) -> None:
super().__init__(*args, **kwargs)


class DbtRunGcpCloudRunJobOperator(DbtRunMixin, DbtGcpCloudRunJobBaseOperator):
"""
Executes a dbt core run command.
Expand Down
16 changes: 14 additions & 2 deletions tests/operators/test_gcp_cloud_run_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
DbtRunOperationGcpCloudRunJobOperator,
DbtSeedGcpCloudRunJobOperator,
DbtSnapshotGcpCloudRunJobOperator,
DbtSourceGcpCloudRunJobOperator,
DbtTestGcpCloudRunJobOperator,
)

Expand Down Expand Up @@ -171,12 +172,13 @@ def test_dbt_gcp_cloud_run_job_build_command():
"seed": DbtSeedGcpCloudRunJobOperator(**BASE_KWARGS),
"build": DbtBuildGcpCloudRunJobOperator(**BASE_KWARGS),
"snapshot": DbtSnapshotGcpCloudRunJobOperator(**BASE_KWARGS),
"source": DbtSourceGcpCloudRunJobOperator(**BASE_KWARGS),
"run-operation": DbtRunOperationGcpCloudRunJobOperator(macro_name="some-macro", **BASE_KWARGS),
}

for command_name, command_operator in result_map.items():
command_operator.build_command(context=MagicMock(), cmd_flags=MagicMock())
if command_name != "run-operation":
if command_name not in ("run-operation", "source"):
assert command_operator.command == [
"dbt",
command_name,
Expand All @@ -185,7 +187,7 @@ def test_dbt_gcp_cloud_run_job_build_command():
"start_time: '{{ data_interval_start.strftime(''%Y%m%d%H%M%S'') }}'\n",
"--no-version-check",
]
else:
elif command_name == "run-operation":
assert command_operator.command == [
"dbt",
command_name,
Expand All @@ -195,6 +197,16 @@ def test_dbt_gcp_cloud_run_job_build_command():
"start_time: '{{ data_interval_start.strftime(''%Y%m%d%H%M%S'') }}'\n",
"--no-version-check",
]
else:
assert command_operator.command == [
"dbt",
command_name,
"freshness",
"--vars",
"end_time: '{{ data_interval_end.strftime(''%Y%m%d%H%M%S'') }}'\n"
"start_time: '{{ data_interval_start.strftime(''%Y%m%d%H%M%S'') }}'\n",
"--no-version-check",
]


@skip_on_empty_operator
Expand Down
Loading