Created
September 8, 2019 06:37
-
-
Save chandulal/32c3bb59ddf5548eca53480850c302a9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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