o-nikolas commented on code in PR #46945: URL: https://github.com/apache/airflow/pull/46945#discussion_r1966402486
########## providers/amazon/tests/unit/amazon/aws/sensors/test_mwaa.py: ########## @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from unittest import mock + +import pytest + +from airflow.exceptions import AirflowException +from airflow.providers.amazon.aws.hooks.mwaa import MwaaHook +from airflow.providers.amazon.aws.sensors.mwaa import MwaaDagRunSensor +from airflow.utils.state import State + +SENSOR_KWARGS = { + "task_id": "test_mwaa_sensor", + "external_env_name": "test_env", + "external_dag_id": "test_dag", + "external_dag_run_id": "test_run_id", +} + + [email protected] +def mock_invoke_rest_api(): + with mock.patch.object(MwaaHook, "invoke_rest_api") as m: + yield m + + +class TestMwaaDagRunSuccessSensor: + def test_init(self): + s_states = {"state1", "state2"} + f_states = {"state3", "state4"} Review Comment: minor nit: But I don't love single character variable names (or even components of a variable name with single characters). I think it's much cleaner an readable to have `success_states` and `failure_states` and it's really not thaaat much longer. ########## providers/amazon/tests/unit/amazon/aws/sensors/test_mwaa.py: ########## @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from unittest import mock + +import pytest + +from airflow.exceptions import AirflowException +from airflow.providers.amazon.aws.hooks.mwaa import MwaaHook +from airflow.providers.amazon.aws.sensors.mwaa import MwaaDagRunSensor +from airflow.utils.state import State + +SENSOR_KWARGS = { + "task_id": "test_mwaa_sensor", + "external_env_name": "test_env", + "external_dag_id": "test_dag", + "external_dag_run_id": "test_run_id", +} + + [email protected] +def mock_invoke_rest_api(): + with mock.patch.object(MwaaHook, "invoke_rest_api") as m: + yield m + + +class TestMwaaDagRunSuccessSensor: + def test_init(self): + s_states = {"state1", "state2"} + f_states = {"state3", "state4"} + sensor = MwaaDagRunSensor(**SENSOR_KWARGS, success_states=s_states, failure_states=f_states) + assert sensor.ext_env_name == SENSOR_KWARGS["external_env_name"] + assert sensor.ext_dag_id == SENSOR_KWARGS["external_dag_id"] + assert sensor.ext_dag_run_id == SENSOR_KWARGS["external_dag_run_id"] + assert set(sensor.success_states) == set(s_states) Review Comment: nit: Does the left side need the coercion to `set`? Don't you already do that inside the sensor init? And the s_states is already a set too? ########## providers/amazon/tests/unit/amazon/aws/sensors/test_mwaa.py: ########## @@ -0,0 +1,72 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from unittest import mock + +import pytest + +from airflow.exceptions import AirflowException +from airflow.providers.amazon.aws.hooks.mwaa import MwaaHook +from airflow.providers.amazon.aws.sensors.mwaa import MwaaDagRunSensor +from airflow.utils.state import State + +SENSOR_KWARGS = { + "task_id": "test_mwaa_sensor", + "external_env_name": "test_env", + "external_dag_id": "test_dag", + "external_dag_run_id": "test_run_id", +} + + [email protected] +def mock_invoke_rest_api(): + with mock.patch.object(MwaaHook, "invoke_rest_api") as m: + yield m + + +class TestMwaaDagRunSuccessSensor: + def test_init(self): + s_states = {"state1", "state2"} + f_states = {"state3", "state4"} + sensor = MwaaDagRunSensor(**SENSOR_KWARGS, success_states=s_states, failure_states=f_states) + assert sensor.ext_env_name == SENSOR_KWARGS["external_env_name"] + assert sensor.ext_dag_id == SENSOR_KWARGS["external_dag_id"] + assert sensor.ext_dag_run_id == SENSOR_KWARGS["external_dag_run_id"] + assert set(sensor.success_states) == set(s_states) + assert set(sensor.failure_states) == set(f_states) + + with pytest.raises(AirflowException): + MwaaDagRunSensor( + **SENSOR_KWARGS, success_states={"state1", "state2"}, failure_states={"state2", "state3"} Review Comment: nit: This feels like a sad case tacked onto the end of a happy path unit test. Maybe split it out into it's own? -- 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]
