ephraimbuddy commented on a change in pull request #20485:
URL: https://github.com/apache/airflow/pull/20485#discussion_r777856210
##########
File path: tests/api_connexion/endpoints/test_dag_run_endpoint.py
##########
@@ -163,6 +163,35 @@ def _create_test_dag_run(self, state='running',
extra_dag=False, commit=True):
session.add_all(dags)
return dag_runs
+ def _create_test_dag_run_with_queued(self, commit=True):
+ dag_runs = []
+ dags = [DagModel(dag_id="TEST_DAG_ID")]
+ dagrun_model_1 = DagRun(
+ dag_id="TEST_DAG_ID",
+ run_id="TEST_DAG_RUN_ID_1",
+ run_type=DagRunType.MANUAL,
+ execution_date=timezone.parse(self.default_time),
+ start_date=timezone.parse(self.default_time),
+ external_trigger=True,
+ state='running',
+ )
+ dag_runs.append(dagrun_model_1)
+ dagrun_model_2 = DagRun(
+ dag_id="TEST_DAG_ID",
+ run_id="TEST_DAG_RUN_ID_2",
+ run_type=DagRunType.MANUAL,
+ execution_date=timezone.parse(self.default_time_2),
+ start_date=timezone.parse(self.default_time),
+ external_trigger=True,
+ state='queued',
+ )
+ dag_runs.append(dagrun_model_2)
+ if commit:
+ with create_session() as session:
+ session.add_all(dag_runs)
+ session.add_all(dags)
+ return dag_runs
Review comment:
I don't think we need this duplication, we can use
`_create_test_dag_run` instead. I understand you want to limit it to 2 dagruns
but that's the essence of the PR, we can filter down to 2.
`_create_test_dag_run` takes `state` argument. You can call it twice or more
with different states thereby creating more dagruns and then test the added
filtering.
##########
File path: tests/api_connexion/endpoints/test_dag_run_endpoint.py
##########
@@ -307,6 +336,41 @@ def test_should_respond_200(self, session):
"total_entries": 2,
}
+ def test_filter_by_state(self, session):
+ self._create_test_dag_run_with_queued()
+ assert session.query(DagRun).count() == 2
+ response = self.client.get(
+ "api/v1/dags/TEST_DAG_ID/dagRuns?state=running,queued",
environ_overrides={'REMOTE_USER': "test"}
+ )
+ assert response.status_code == 200
+ assert response.json == {
Review comment:
You may not need to check and list every fields. You can check important
things like total returned, and states of the items returned
##########
File path: tests/api_connexion/endpoints/test_dag_run_endpoint.py
##########
@@ -307,6 +336,41 @@ def test_should_respond_200(self, session):
"total_entries": 2,
}
+ def test_filter_by_state(self, session):
+ self._create_test_dag_run_with_queued()
Review comment:
```suggestion
self._create_test_dag_run()
self._create_test_dag_run(state='queued')
```
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]