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/08/03 13:15:12 UTC

[GitHub] [airflow] feluelle commented on a change in pull request #9817: S3 upload session complete sensor

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



##########
File path: tests/providers/amazon/aws/sensors/test_s3_keys_unchanged.py
##########
@@ -0,0 +1,128 @@
+#
+# 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 datetime import datetime
+from unittest import TestCase, mock
+
+from freezegun import freeze_time
+
+from airflow.models.dag import DAG, AirflowException
+from airflow.providers.amazon.aws.sensors.s3_keys_unchanged import S3KeysUnchangedSensor
+
+TEST_DAG_ID = 'unit_tests_aws_sensor'
+DEFAULT_DATE = datetime(2015, 1, 1)
+
+
+class TestS3KeysUnchangedSensor(TestCase):
+
+    def setUp(self):
+        args = {
+            'owner': 'airflow',
+            'start_date': DEFAULT_DATE,
+        }
+        dag = DAG(TEST_DAG_ID + 'test_schedule_dag_once', default_args=args)
+        dag.schedule_interval = '@once'
+        self.dag = dag
+
+        self.sensor = S3KeysUnchangedSensor(
+            task_id='sensor_1',
+            bucket_name='test-bucket',
+            prefix='test-prefix/path',
+            inactivity_period=12,
+            poke_interval=0.1,
+            min_objects=1,
+            allow_delete=False,
+            dag=self.dag
+        )
+
+    def test_reschedule_mode_not_allowed(self):
+        with self.assertRaises(ValueError):
+            S3KeysUnchangedSensor(
+                task_id='sensor_2',
+                bucket_name='test-bucket',
+                prefix='test-prefix/path',
+                poke_interval=0.1,
+                mode='reschedule',
+                dag=self.dag
+            )
+
+    @freeze_time(DEFAULT_DATE, auto_tick_seconds=10)
+    def test_files_deleted_between_pokes_throw_error(self):
+        self.sensor.is_keys_unchanged({'a', 'b'})
+        with self.assertRaises(AirflowException):
+            self.sensor.is_keys_unchanged({'a'})
+
+    @freeze_time(DEFAULT_DATE)
+    def test_files_deleted_between_pokes_allow_delete(self):
+        self.sensor = S3KeysUnchangedSensor(
+            task_id='sensor_2',
+            bucket_name='test-bucket',
+            prefix='test-prefix/path',
+            inactivity_period=12,
+            poke_interval=0.1,
+            min_objects=1,
+            allow_delete=True,
+            dag=self.dag
+        )

Review comment:
       ```suggestion
           self.sensor.allow_delete = True
   ```




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