Skip to content

Commit

Permalink
add test for templated field
Browse files Browse the repository at this point in the history
  • Loading branch information
romsharon98 committed Feb 4, 2024
1 parent 9a5a6c4 commit c6e9868
Showing 1 changed file with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,33 @@ def test_job_create_multiple(self, aws_hook, gcp_hook):
# (could be anything else) just to test if the templating works for all
# fields
@pytest.mark.db_test
@pytest.mark.parametrize(
"body, excepted",
[
(
{"description": "{{ dag.dag_id }}"},
{
"description": "TestGcpStorageTransferJobCreateOperator_test_templates",
},
),
("{{ dag.dag_id }}", "TestGcpStorageTransferJobCreateOperator_test_templates"),
],
)
@mock.patch(
"airflow.providers.google.cloud.operators.cloud_storage_transfer_service.CloudDataTransferServiceHook"
)
def test_templates(self, _, create_task_instance_of_operator):
def test_templates(self, _, create_task_instance_of_operator, body, excepted):
dag_id = "TestGcpStorageTransferJobCreateOperator_test_templates"
ti = create_task_instance_of_operator(
CloudDataTransferServiceCreateJobOperator,
dag_id=dag_id,
body={"description": "{{ dag.dag_id }}"},
body=body,
gcp_conn_id="{{ dag.dag_id }}",
aws_conn_id="{{ dag.dag_id }}",
task_id="task-id",
)
ti.render_templates()
assert dag_id == getattr(ti.task, "body")[DESCRIPTION]
assert excepted == getattr(ti.task, "body")
assert dag_id == getattr(ti.task, "gcp_conn_id")
assert dag_id == getattr(ti.task, "aws_conn_id")

Expand Down

0 comments on commit c6e9868

Please sign in to comment.