Skip to content

Commit

Permalink
Create unittest to check expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
joppevos committed Nov 1, 2023
1 parent 4e64a9f commit 8f40d5a
Showing 1 changed file with 12 additions and 36 deletions.
48 changes: 12 additions & 36 deletions tests/operators/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from packaging import version
from pendulum import datetime


from cosmos.config import ProfileConfig
from cosmos.operators.local import (
DbtLocalBaseOperator,
Expand Down Expand Up @@ -415,39 +416,14 @@ def test_calculate_openlineage_events_completes_openlineage_errors(mock_processo
assert err_msg in caplog.text


# write a test to check our new template_fields "full_refresh" behavior
# @pytest.mark.integration
def test_run_operator_foo():
params = {"full_refresh": False}
with DAG("test-id-1", start_date=datetime(2022, 1, 1), params=params) as dag:
run_operator = DbtRunLocalOperator(
profile_config=real_profile_config,
project_dir=DBT_PROJ_DIR,
task_id="run",
dbt_cmd_flags=["--models", "stg_customers"],
install_deps=True,
append_env=True,
full_refresh="{{ params.full_refresh }}",
)
run_operator
dag_run = run_test_dag(dag)
templates = dag_run.get_task_instances()[0]
assert templates[0][0] == "full_refresh"
# Make sure all the jinja templates are rendered

# Compare full refresh rendered value with expected value
# assert run_operator.full_refresh == "False"


# @pytest.mark.parametrize(
# "operator_class,kwargs,expected_call_kwargs",
# [
# (DbtRunLocalOperator, {"full_refresh": "foo"}, {"context": {}, "cmd_flags": ["--full-refresh"]}),
# ],
# )
# @patch("cosmos.operators.local.DbtLocalBaseOperator.build_and_run_cmd")
# def test_operator_execute_with_flags(mock_build_and_run_cmd, operator_class, kwargs, expected_call_kwargs):
# task = operator_class(profile_config=profile_config, task_id="my-task", project_dir="my/dir", **kwargs)
# # check if the rendered value matches the expected value
#
#
@pytest.mark.parametrize(
"operator_class,expected_template",
[
(DbtSeedLocalOperator, ("env", "vars", "full_refresh")),
(DbtRunLocalOperator, ("env", "vars", "full_refresh")),
],
)
def test_dbt_base_operator_template_fields(operator_class, expected_template):
# Check if value of template fields is what we expect for the operators we're validating
dbt_base_operator = operator_class(profile_config=profile_config, task_id="my-task", project_dir="my/dir")
assert dbt_base_operator.template_fields == expected_template

0 comments on commit 8f40d5a

Please sign in to comment.