vincbeck commented on code in PR #74293:
URL: https://github.com/apache/airflow/pull/74293#discussion_r4338669408
##########
providers/amazon/tests/unit/amazon/aws/triggers/test_s3.py:
##########
@@ -256,3 +260,201 @@ async def test_run_pending(self, mock_is_keys_unchanged,
mock_client):
# TriggerEvent was not returned
assert task.done() is False
asyncio.get_event_loop().stop()
+
+
+def _head(etag, last_modified=None, size=None):
+ """Build a head_object response pointing at ``etag``. ``None`` means the
key is absent."""
+ if etag is None:
+ return None
+ return {"ETag": etag, "LastModified": last_modified, "ContentLength": size}
+
+
+async def _collect(trigger, count, timeout=10.0):
+ """Pull up to ``count`` payloads off the trigger, giving up after
``timeout``."""
+ from contextlib import aclosing, suppress
+
+ payloads = []
+ generator = trigger.run()
+ async with aclosing(generator):
+
+ async def pump():
+ async for event in generator:
+ payloads.append(event.payload)
+ if len(payloads) >= count:
+ return
+
+ with suppress(asyncio.TimeoutError):
+ await asyncio.wait_for(pump(), timeout=timeout)
+ return payloads
+
+
+@async_mock.patch("airflow.providers.amazon.aws.triggers.s3.S3Hook.get_async_conn")
+class TestS3KeyUpdateTrigger:
+ @staticmethod
+ def _conn(mock_get_async_conn):
+ mock_get_async_conn.return_value.__aenter__.return_value =
async_mock.AsyncMock()
+
+ def test_serialize_round_trip(self, mock_get_async_conn):
+ trigger = S3KeyUpdateTrigger(
+ bucket_name="my-bucket",
+ bucket_key="reports/daily.csv",
+ aws_conn_id="my_conn",
+ poke_interval=5,
+ region_name="eu-west-1",
+ )
+ classpath, kwargs = trigger.serialize()
+
+ assert classpath ==
"airflow.providers.amazon.aws.triggers.s3.S3KeyUpdateTrigger"
+ assert kwargs == {
+ "bucket_name": "my-bucket",
+ "bucket_key": "reports/daily.csv",
+ "aws_conn_id": "my_conn",
+ "poke_interval": 5,
+ "region_name": "eu-west-1",
+ "verify": None,
+ "botocore_config": None,
+ "last_seen_etag": None,
+ "hook_params": {},
+ }
Review Comment:
Fair enough
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]