dstandish commented on a change in pull request #5372: [AIRFLOW-3057] add 
prev_*_date_success to template context
URL: https://github.com/apache/airflow/pull/5372#discussion_r291073585
 
 

 ##########
 File path: tests/models/test_taskinstance.py
 ##########
 @@ -992,3 +994,103 @@ def success_handler(self, context):
         self.assertEqual(cw.task_state_in_callback, State.RUNNING)
         ti.refresh_from_db()
         self.assertEqual(ti.state, State.SUCCESS)
+
+    def _test_previous_dates(self, schedule_interval: Union[str, 
datetime.timedelta, None], catchup: bool,
+                             object_: str) -> None:
+        dag_id = 'test_previous_dates'
+        dag = models.DAG(dag_id=dag_id, schedule_interval=schedule_interval, 
catchup=catchup)
+        task = DummyOperator(task_id='task', dag=dag, start_date=DEFAULT_DATE)
+
+        d1 = '2019-01-01T00:00:00+00:00'
+        d2 = '2019-01-02T00:00:00+00:00'
+        d3 = '2019-01-03T00:00:00+00:00'
+
+        with create_session() as session:  # type: Session
+
+            # session.query(DagRun).all().filter(DagRun.dag_id == dag_id).all()
+            # session.query(TI).filter(TI.dag_id == dag_id).delete()
+            # session.commit()
+            dag.create_dagrun(
+                run_id='scheduled__{}'.format(d1),
+                state=State.SUCCESS,
+                execution_date=pendulum.parse(d1),
+                start_date=pendulum.utcnow(),
+                session=session
+            )
+
+            dag.create_dagrun(
+                run_id='scheduled__{}'.format(d2),
+                state=State.FAILED,
+                execution_date=pendulum.parse(d2),
+                start_date=pendulum.utcnow(),
+                session=session
+            )
+
+            dag.create_dagrun(
+                run_id='scheduled__{}'.format(d3),
+                state=State.SUCCESS,
+                execution_date=pendulum.parse(d3),
+                start_date=pendulum.utcnow(),
+                session=session
+            )
+
+            t1 = TI(task=task, execution_date=pendulum.parse(d1))
+            t1.set_state(state=State.SUCCESS, session=session)
+
+            t2 = TI(task=task, execution_date=pendulum.parse(d2))
+            t2.set_state(state=State.SUCCESS, session=session)
+
+            t3 = TI(task=task, execution_date=pendulum.parse(d3))
+            t3.set_state(state=State.SUCCESS, session=session)
+
+            if object_ == 'previous_ti':
 
 Review comment:
   Yeah I thought about doing it that way, but it also uses the dates `d1`, 
`d2`, `d3`.  I thought about making a class and class attributes so that I 
would not have to return so many objects but I guess I can just throw them in a 
dictionary and call it a day.
   
   Alternatively, could make a separate test class for these prev dates / TIs 
tests, make this helper the setup method, store the useful objects as 
attributes, where they can be used by these individual tests.  LMK your 
thoughts.  
   
   But yeah either way I should make this better.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to