Skip to content

Instantly share code, notes, and snippets.

@chandulal
Created September 8, 2019 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chandulal/32c3bb59ddf5548eca53480850c302a9 to your computer and use it in GitHub Desktop.
Save chandulal/32c3bb59ddf5548eca53480850c302a9 to your computer and use it in GitHub Desktop.
def test_xcom_in_templated_field(self):
dag_id = 'hello_world_xcoms'
dag = self.dagbag.get_dag(dag_id)
push_to_xcoms_task = dag.get_task('push_to_xcoms')
execution_date = datetime.now()
push_to_xcoms_ti = TaskInstance(task=push_to_xcoms_task, execution_date=execution_date)
context = push_to_xcoms_ti.get_template_context()
push_to_xcoms_task.execute(context)
templated_xcoms_value_task = dag.get_task('templated_xcoms_value')
templated_xcoms_value_ti = TaskInstance(task=templated_xcoms_value_task, execution_date=execution_date)
context = templated_xcoms_value_ti.get_template_context()
bash_operator_templated_field = 'bash_command'
rendered_template = templated_xcoms_value_task.render_template
bash_command_value = getattr(templated_xcoms_value_task, bash_operator_templated_field)
bash_command_rendered_value = rendered_template(bash_operator_templated_field, bash_command_value, context)
self.assertEqual(bash_command_rendered_value, 'echo dummyValue')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment