def test_pull_existing_tags_each_value(self): context = self.ti.get_template_context() set_xcom_tags(context, TEST_KEY_ONE, TEST_VALUE_ALL_DICT) returned_xcom_tasks = get_many_xcom_tags( dag_ids=self.ti.dag_id, values=TEST_VALUE_1_DICT, ) # assert list returned is of length 1, xcom match was found for value 1 self.assertEqual(len(returned_xcom_tasks), 1) returned_xcom_tasks = get_many_xcom_tags( dag_ids=self.ti.dag_id, values=TEST_VALUE_2_DICT, ) # assert list returned is of length 1, xcom match was found for value 2 self.assertEqual(len(returned_xcom_tasks), 1) returned_xcom_tasks = get_many_xcom_tags( dag_ids=self.ti.dag_id, values=TEST_VALUE_3_DICT, ) # assert list returned is of length 1, xcom match was found for value 3 self.assertEqual(len(returned_xcom_tasks), 1)
def test_pull_existing_tags_task_id(self): context = self.ti.get_template_context() set_xcom_tags(context, TEST_KEY_ONE, TEST_VALUE_ALL_DICT) returned_xcom_tasks = get_many_xcom_tags(task_ids=self.ti.task_id, ) # assert list returned is of length 1, xcom match was found self.assertEqual(len(returned_xcom_tasks), 1)
def test_pull_existing_tags_multiple(self): context = self.ti.get_template_context() set_xcom_tags(context, TEST_KEY_ONE, TEST_VALUE_ALL_DICT) set_xcom_tags(context, TEST_KEY_TWO, TEST_VALUE_ALL_DICT) returned_xcom_tasks = get_many_xcom_tags(dag_ids=self.ti.dag_id, ) # assert list returned is not empty, xcom matches were found self.assertEqual(len(returned_xcom_tasks), 2)
def test_pull_existing_tags_exec_dates(self): context = self.ti.get_template_context() set_xcom_tags(context, TEST_KEY_ONE, TEST_VALUE_ALL_DICT) returned_xcom_tasks = get_many_xcom_tags( min_execution_date=self.ti.execution_date, max_execution_date=self.ti.execution_date, dag_ids=self.ti.dag_id, ) # assert list returned is of length 1, xcom match was found for date = self.assertEqual(len(returned_xcom_tasks), 1) returned_xcom_tasks = get_many_xcom_tags( min_execution_date=timezone.datetime(2020, 5, 31, 19, 58, 39, 00), max_execution_date=timezone.datetime(2050, 6, 18, 19, 58, 39, 00), dag_ids=self.ti.dag_id, ) # assert list returned is of length 1, xcom match was found for range self.assertEqual(len(returned_xcom_tasks), 1) returned_xcom_tasks = get_many_xcom_tags( min_execution_date=timezone.datetime(2050, 6, 18, 19, 58, 39, 00), dag_ids=self.ti.dag_id, ) # assert list returned is of length 0, xcom match was not found for min self.assertEqual(len(returned_xcom_tasks), 0) returned_xcom_tasks = get_many_xcom_tags( max_execution_date=timezone.datetime(2020, 5, 31, 19, 58, 39, 00), dag_ids=self.ti.dag_id, ) # assert list returned is of length 0, xcom match was not found for max self.assertEqual(len(returned_xcom_tasks), 0)
def get_value_via_custom_xcom(**context): print("XCom custom get_many testing") returned_xcom_tasks = get_many_xcom_tags( min_execution_date=timezone.datetime(2020, 6, 18, 19, 58, 39, 00), max_execution_date=context["ti"].execution_date, dag_ids="example_custom_xcom_use", key="bbb_tags", values=json.loads('{ "activity":"transfer", "level":"source" }'), ) print("The following tasks were returned: ", returned_xcom_tasks) for match in returned_xcom_tasks: print("Task match: ", match.task_id) print("For this value: ", match.value)
def test_pull_nonexistent_tags(self): returned_xcom_tasks = get_many_xcom_tags(dag_ids=self.ti.dag_id, ) # assert list returned is of length 0, no xcom matched self.assertEqual(len(returned_xcom_tasks), 0)