Skip to content

Commit 9162b2a

Browse files
Marthe Van Den Hendetomasfarias
authored andcommitted
include PR feedback
1 parent e930b7b commit 9162b2a

4 files changed

Lines changed: 69 additions & 28 deletions

File tree

tests/operators/test_dbt_build.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -241,22 +241,32 @@ def test_full_refresh_in_template_fields():
241241
assert "full_refresh" in DbtBuildOperator.template_fields
242242

243243

244-
def test_full_refresh_templated():
244+
@pytest.mark.parametrize(
245+
"native,param_value,expected",
246+
[
247+
(False, "True", "True"),
248+
(True, True, True),
249+
],
250+
)
251+
def test_full_refresh_templated(native, param_value, expected):
245252
"""Test that full_refresh can be templated with Jinja.
246253
247-
Airflow renders template fields as strings, so the operator receives a
248-
string after rendering. The string-to-bool coercion happens in
249-
TableMutabilityConfig and is tested in test_configs.py.
254+
With default rendering, Airflow renders to strings. With
255+
render_template_as_native_obj=True, native Python types are preserved.
250256
"""
251257
import pendulum
252258
from airflow.models.dag import DAG
253259

254-
dag = DAG(dag_id="test_dag", start_date=pendulum.datetime(2025, 1, 1))
260+
dag = DAG(
261+
dag_id="test_dag",
262+
start_date=pendulum.datetime(2025, 1, 1),
263+
render_template_as_native_obj=native,
264+
)
255265
op = DbtBuildOperator(
256266
task_id="dbt_task",
257267
full_refresh="{{ params.full_refresh }}",
258268
dag=dag,
259269
)
260-
context = {"params": {"full_refresh": "True"}}
270+
context = {"params": {"full_refresh": param_value}}
261271
op.render_template_fields(context)
262-
assert op.full_refresh == "True"
272+
assert op.full_refresh == expected

tests/operators/test_dbt_compile.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from pathlib import Path
44
from textwrap import dedent
55

6+
import pytest
67
from dbt.contracts.results import RunStatus
78

89
from airflow_dbt_python.operators.dbt import DbtCompileOperator
@@ -213,22 +214,32 @@ def test_full_refresh_in_template_fields():
213214
assert "full_refresh" in DbtCompileOperator.template_fields
214215

215216

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):
217225
"""Test that full_refresh can be templated with Jinja.
218226
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.
222229
"""
223230
import pendulum
224231
from airflow.models.dag import DAG
225232

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+
)
227238
op = DbtCompileOperator(
228239
task_id="dbt_task",
229240
full_refresh="{{ params.full_refresh }}",
230241
dag=dag,
231242
)
232-
context = {"params": {"full_refresh": "True"}}
243+
context = {"params": {"full_refresh": param_value}}
233244
op.render_template_fields(context)
234-
assert op.full_refresh == "True"
245+
assert op.full_refresh == expected

tests/operators/test_dbt_run.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -435,21 +435,31 @@ def test_full_refresh_in_template_fields():
435435
assert "full_refresh" in DbtRunOperator.template_fields
436436

437437

438-
def test_full_refresh_templated():
438+
@pytest.mark.parametrize(
439+
"native,param_value,expected",
440+
[
441+
(False, "True", "True"),
442+
(True, True, True),
443+
],
444+
)
445+
def test_full_refresh_templated(native, param_value, expected):
439446
"""Test that full_refresh can be templated with Jinja.
440447
441-
Airflow renders template fields as strings, so the operator receives a
442-
string after rendering. The string-to-bool coercion happens in
443-
TableMutabilityConfig and is tested in test_configs.py.
448+
With default rendering, Airflow renders to strings. With
449+
render_template_as_native_obj=True, native Python types are preserved.
444450
"""
445451
from airflow.models.dag import DAG
446452

447-
dag = DAG(dag_id="test_dag", start_date=pendulum.datetime(2025, 1, 1))
453+
dag = DAG(
454+
dag_id="test_dag",
455+
start_date=pendulum.datetime(2025, 1, 1),
456+
render_template_as_native_obj=native,
457+
)
448458
op = DbtRunOperator(
449459
task_id="dbt_task",
450460
full_refresh="{{ params.full_refresh }}",
451461
dag=dag,
452462
)
453-
context = {"params": {"full_refresh": "True"}}
463+
context = {"params": {"full_refresh": param_value}}
454464
op.render_template_fields(context)
455-
assert op.full_refresh == "True"
465+
assert op.full_refresh == expected

tests/operators/test_dbt_seed.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,22 +334,32 @@ def test_full_refresh_in_template_fields():
334334
assert "full_refresh" in DbtSeedOperator.template_fields
335335

336336

337-
def test_full_refresh_templated():
337+
@pytest.mark.parametrize(
338+
"native,param_value,expected",
339+
[
340+
(False, "True", "True"),
341+
(True, True, True),
342+
],
343+
)
344+
def test_full_refresh_templated(native, param_value, expected):
338345
"""Test that full_refresh can be templated with Jinja.
339346
340-
Airflow renders template fields as strings, so the operator receives a
341-
string after rendering. The string-to-bool coercion happens in
342-
TableMutabilityConfig and is tested in test_configs.py.
347+
With default rendering, Airflow renders to strings. With
348+
render_template_as_native_obj=True, native Python types are preserved.
343349
"""
344350
import pendulum
345351
from airflow.models.dag import DAG
346352

347-
dag = DAG(dag_id="test_dag", start_date=pendulum.datetime(2025, 1, 1))
353+
dag = DAG(
354+
dag_id="test_dag",
355+
start_date=pendulum.datetime(2025, 1, 1),
356+
render_template_as_native_obj=native,
357+
)
348358
op = DbtSeedOperator(
349359
task_id="dbt_task",
350360
full_refresh="{{ params.full_refresh }}",
351361
dag=dag,
352362
)
353-
context = {"params": {"full_refresh": "True"}}
363+
context = {"params": {"full_refresh": param_value}}
354364
op.render_template_fields(context)
355-
assert op.full_refresh == "True"
365+
assert op.full_refresh == expected

0 commit comments

Comments
 (0)