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



##########
File path: tests/providers/amazon/aws/hooks/test_s3.py
##########
@@ -313,6 +313,25 @@ def test_copy_object_acl(self, s3_bucket):
             assert ((response['Grants'][0]['Permission'] == 'FULL_CONTROL') and
                     (len(response['Grants']) == 1))
 
+    @mock_s3
+    def test_delete_bucket(self, s3_bucket):
+        # assert if the bucket is created
+        mock_hook = S3Hook()
+        mock_hook.create_bucket(bucket_name=s3_bucket)
+        assert mock_hook.check_for_bucket(bucket_name=s3_bucket)
+        # add keys to bucket
+        for i in range(0, 3):
+            mock_hook.load_file_obj(

Review comment:
       Actually, I would remove this code / the for-loop, because that is what 
you would test in the system test not the unit test. The unit is the delete 
operation only.
   
   Because you are mocking here you don't need to "load"  data to s3 - it won't 
be loaded anyway.

##########
File path: tests/providers/amazon/aws/operators/test_s3_bucket.py
##########
@@ -0,0 +1,63 @@
+#
+# 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 io
+import os
+import unittest
+
+from moto import mock_s3
+
+from airflow.providers.amazon.aws.hooks.s3 import S3Hook
+from airflow.providers.amazon.aws.operators.s3_bucket import 
S3CreateBucketOperator, S3DeleteBucketOperator
+
+BUCKET_NAME = os.environ.get("BUCKET_NAME", "test-airflow-bucket")
+TASK_ID = os.environ.get("TASK_ID", "test-s3-operator")
+
+
+class TestS3CreateBucketOperator(unittest.TestCase):
+    @mock_s3
+    def test_execute(self):
+        mock_hook = S3Hook()
+        # execute s3 bucket create operator
+        op = S3CreateBucketOperator(bucket_name=BUCKET_NAME, task_id=TASK_ID)
+        op.execute({})
+        # assert if the bucket has been created
+        self.assertTrue(mock_hook.check_for_bucket(bucket_name=BUCKET_NAME))
+
+
+class TestS3DeleteBucketOperator(unittest.TestCase):
+    @mock_s3
+    def test_execute(self):

Review comment:
       Same here, please. :)

##########
File path: tests/providers/amazon/aws/hooks/test_s3.py
##########
@@ -313,6 +313,25 @@ def test_copy_object_acl(self, s3_bucket):
             assert ((response['Grants'][0]['Permission'] == 'FULL_CONTROL') and
                     (len(response['Grants']) == 1))
 
+    @mock_s3
+    def test_delete_bucket(self, s3_bucket):

Review comment:
       Can you split this test up into two test cases. One in case the bucket 
does not exist and one for the regular case - it exists.




----------------------------------------------------------------
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:
[email protected]


Reply via email to