From 8f40d5a85278924b1543cc9bed28c68ffc1034fb Mon Sep 17 00:00:00 2001 From: Joppe Vos Date: Wed, 1 Nov 2023 11:25:30 +0100 Subject: [PATCH] Create unittest to check expectations --- tests/operators/test_local.py | 48 +++++++++-------------------------- 1 file changed, 12 insertions(+), 36 deletions(-) diff --git a/tests/operators/test_local.py b/tests/operators/test_local.py index 1f9add663..1ce9047c2 100644 --- a/tests/operators/test_local.py +++ b/tests/operators/test_local.py @@ -14,6 +14,7 @@ from packaging import version from pendulum import datetime + from cosmos.config import ProfileConfig from cosmos.operators.local import ( DbtLocalBaseOperator, @@ -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