|
3 | 3 | from pathlib import Path |
4 | 4 | from textwrap import dedent |
5 | 5 |
|
| 6 | +import pytest |
6 | 7 | from dbt.contracts.results import RunStatus |
7 | 8 |
|
8 | 9 | from airflow_dbt_python.operators.dbt import DbtCompileOperator |
@@ -213,22 +214,32 @@ def test_full_refresh_in_template_fields(): |
213 | 214 | assert "full_refresh" in DbtCompileOperator.template_fields |
214 | 215 |
|
215 | 216 |
|
216 | | -def test_full_refresh_templated(): |
| 217 | +@pytest.mark.parametrize( |
| 218 | + "native,param_value,expected", |
| 219 | + [ |
| 220 | + (False, "True", "True"), |
| 221 | + (True, True, True), |
| 222 | + ], |
| 223 | +) |
| 224 | +def test_full_refresh_templated(native, param_value, expected): |
217 | 225 | """Test that full_refresh can be templated with Jinja. |
218 | 226 |
|
219 | | - Airflow renders template fields as strings, so the operator receives a |
220 | | - string after rendering. The string-to-bool coercion happens in |
221 | | - TableMutabilityConfig and is tested in test_configs.py. |
| 227 | + With default rendering, Airflow renders to strings. With |
| 228 | + render_template_as_native_obj=True, native Python types are preserved. |
222 | 229 | """ |
223 | 230 | import pendulum |
224 | 231 | from airflow.models.dag import DAG |
225 | 232 |
|
226 | | - dag = DAG(dag_id="test_dag", start_date=pendulum.datetime(2025, 1, 1)) |
| 233 | + dag = DAG( |
| 234 | + dag_id="test_dag", |
| 235 | + start_date=pendulum.datetime(2025, 1, 1), |
| 236 | + render_template_as_native_obj=native, |
| 237 | + ) |
227 | 238 | op = DbtCompileOperator( |
228 | 239 | task_id="dbt_task", |
229 | 240 | full_refresh="{{ params.full_refresh }}", |
230 | 241 | dag=dag, |
231 | 242 | ) |
232 | | - context = {"params": {"full_refresh": "True"}} |
| 243 | + context = {"params": {"full_refresh": param_value}} |
233 | 244 | op.render_template_fields(context) |
234 | | - assert op.full_refresh == "True" |
| 245 | + assert op.full_refresh == expected |
0 commit comments