You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/12/16 15:42:17 UTC

[GitHub] [airflow] feluelle commented on a change in pull request #13049: Add S3KeySizeSensor

feluelle commented on a change in pull request #13049:
URL: https://github.com/apache/airflow/pull/13049#discussion_r544402273



##########
File path: tests/providers/amazon/aws/sensors/test_s3_key.py
##########
@@ -121,3 +121,30 @@ def test_poke_wildcard(self, mock_hook):
 
         mock_check_for_wildcard_key.return_value = True
         self.assertTrue(op.poke(None))
+
+
+class TestS3KeySizeSensor(unittest.TestCase):
+    @mock.patch('airflow.providers.amazon.aws.sensors.s3_key.S3Hook')
+    def test_poke(self, mock_hook):
+        op = S3KeySizeSensor(task_id='s3_key_sensor', bucket_key='s3://test_bucket/file')
+
+        mock_check_for_key = mock_hook.return_value.check_for_key
+        mock_check_for_key.return_value = False
+        self.assertFalse(op.poke(None))
+
+        mock_check_for_key.assert_called_once_with(op.bucket_key, op.bucket_name)
+        mock_hook.return_value.check_for_key.return_value = True
+        self.assertFalse(op.poke(None))
+
+        mock_paginator = mock.Mock()
+        mock_paginator.paginate.return_value = []
+        mock_conn = mock.Mock()
+        mock_conn.return_value.get_paginator.return_value = mock_paginator
+        mock_hook.return_value.get_conn = mock_conn
+        mock_paginator.paginate.return_value = [{"Contents": [{"Size": 0}]}]
+        self.assertFalse(op.poke(None))
+
+        mock_paginator.paginate.return_value = [{"Contents": [{"Size": 10}]}]
+        self.assertTrue(op.poke(None))
+        mock_check_for_key.return_value = False
+        self.assertFalse(op.poke(None))

Review comment:
       Please split these tests into separate test functions. This makes it a lot clearer what you test.




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