uranusjr commented on a change in pull request #17839:
URL: https://github.com/apache/airflow/pull/17839#discussion_r700507659
##########
File path: tests/api_connexion/endpoints/test_dag_run_endpoint.py
##########
@@ -1154,3 +1154,91 @@ def test_should_raises_403_unauthorized(self):
environ_overrides={'REMOTE_USER': "test_view_dags"},
)
assert response.status_code == 403
+
+
+class TestPostSetDagRunState(TestDagRunEndpoint):
+ @parameterized.expand([("failed",), ("success",)])
+ @pytest.fixture(scope="module")
+ def test_should_respond_200(self, state, dag_maker):
+ dag_id = "TEST_DAG_ID"
+ with create_session() as session:
+ dag = DagModel(dag_id=dag_id)
+ dag_run = dag_maker.create_dagrun()
+ session.add(dag)
+ session.add(dag_run)
Review comment:
> How can I inject dag_maker […]?
Just include `dag_maker` as an argument. Pytest magically picks the argument
up and injects the fixture into the function. But to make the test compatible
with pytest, you need to use `pytest.mark.parametrize` instead of
`parameterized.expand`.
So something like
```python
@pytest.mark.parametrize("state", [...])
def test_should_respond_200(self, dag_maker, state):
...
```
> What is the purpose of DummyOperator here, and why run in separately in a
context manager from `dag_maker.create_dagrun()`?
The DummyOperator will be included as a part of the DAG, similar to
```python
with DAG(...):
MyOperator(...)
# The above is equivalent to
# dag = DAG(...)
# MyOperator(..., dag=dag)
```
It’s not actually used anywhere in the test, so technically you can just do
```python
with dag_maker(...):
pass
```
A DAG without any operators is kind of weird, but allowed.
--
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]