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 2021/01/04 10:14:29 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_r551217261



##########
File path: tests/providers/amazon/aws/sensors/test_s3_key.py
##########
@@ -121,3 +121,50 @@ 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_check_for_key_false(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)

Review comment:
       ```suggestion
       @mock.patch('airflow.providers.amazon.aws.sensors.s3_key.S3Hook.check_for_key', return_value=False)
       def test_poke_check_for_key_false(self, mock_check_for_key):
           op = S3KeySizeSensor(task_id='s3_key_sensor', bucket_key='s3://test_bucket/file')
   
           has_key = op.poke(context=None)
   
           assert not has_key
           mock_check_for_key.assert_called_once_with(op.bucket_key, op.bucket_name)
   ```
   You only need to mock the `check_for_key` method, right? So we can do this directly in `mock.patch` and also specify the return value for it. WDYT?

##########
File path: tests/providers/amazon/aws/sensors/test_s3_key.py
##########
@@ -121,3 +121,50 @@ 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_check_for_key_false(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.patch('airflow.providers.amazon.aws.sensors.s3_key.S3Hook')
+    def test_poke_get_files_false(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_hook.return_value.check_for_key.return_value = True
+        mock_get_files = mock.Mock()
+        mock_get_files.return_value = False
+        self.assertFalse(op.poke(None))
+        mock_check_for_key.assert_called_once_with(op.bucket_key, op.bucket_name)

Review comment:
       Same here.




----------------------------------------------------------------
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