mik-laj commented on a change in pull request #9503:
URL: https://github.com/apache/airflow/pull/9503#discussion_r447731133



##########
File path: tests/api_connexion/test_parameters.py
##########
@@ -1,69 +0,0 @@
-# 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.
-
-import unittest
-from unittest import mock
-
-from pendulum import DateTime
-from pendulum.tz.timezone import Timezone
-
-from airflow.api_connexion.exceptions import BadRequest
-from airflow.api_connexion.parameters import format_datetime, format_parameters
-from airflow.utils import timezone
-
-
-class TestDateTimeParser(unittest.TestCase):
-
-    def setUp(self) -> None:
-        self.default_time = '2020-06-13T22:44:00+00:00'
-        self.default_time_2 = '2020-06-13T22:44:00Z'
-
-    def test_works_with_datestring_ending_00_00(self):
-        datetime = format_datetime(self.default_time)
-        datetime2 = timezone.parse(self.default_time)
-        assert datetime == datetime2
-        assert datetime.isoformat() == self.default_time
-
-    def test_works_with_datestring_ending_with_zed(self):
-        datetime = format_datetime(self.default_time_2)
-        datetime2 = timezone.parse(self.default_time_2)
-        assert datetime == datetime2
-        assert datetime.isoformat() == self.default_time  # python uses +00:00 
instead of Z
-
-    def test_raises_400_for_invalid_arg(self):
-        invalid_datetime = '2020-06-13T22:44:00P'
-        with self.assertRaises(BadRequest):
-            format_datetime(invalid_datetime)
-
-
-class TestFormatParameters(unittest.TestCase):

Review comment:
       You can use mock.MagicMock, if you have no function. Creating a fake 
function in testing is an other but also a good solution.
   ```python
   import unittest
   from unittest import mock
   
   from airflow.api_connexion.exceptions import BadRequest
   from airflow.api_connexion.parameters import format_parameters
   
   
   class TestFormatParameters(unittest.TestCase):
   
       def test_should_works_with_datetime_formatter(self):
           format_fn = mock.MagicMock()
           decorator = format_parameters({"param_a": format_fn})
           endpoint = mock.MagicMock()
           decorated_endpoint = decorator(endpoint)
   
           decorated_endpoint(param_a="PARAM_A")
   
           endpoint.assert_called_once_with(param_a=format_fn.return_value)
           format_fn.assert_called_once_with("PARAM_A")
   
       def test_should_propagate_exceptions(self):
           format_fn = mock.MagicMock(side_effect=BadRequest)
           decorator = format_parameters({"param_a": format_fn})
           endpoint = mock.MagicMock()
           decorated_endpoint = decorator(endpoint)
   
           with self.assertRaises(BadRequest):
               decorated_endpoint(param_a='PARAM_A')
   
           format_fn.assert_called_once_with("PARAM_A")
   ```




----------------------------------------------------------------
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:
us...@infra.apache.org


Reply via email to