Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ async def is_keys_unchanged_async(
if current_num_objects >= min_objects:
success_message = (
f"SUCCESS: Sensor found {current_num_objects} objects at {path}. "
"Waited at least {inactivity_period} seconds, with no new objects uploaded."
f"Waited at least {inactivity_period} seconds, with no new objects uploaded."
)
self.log.info(success_message)
return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def poke(self, context: Context) -> bool:
item_attribute_value = response["Item"][self.attribute_name]
self.log.info("Response: %s", response)
self.log.info("Want: %s = %s", self.attribute_name, self.attribute_value)
self.log.info("Got: {response['Item'][self.attribute_name]} = %s", item_attribute_value)
self.log.info("Got: %s = %s", self.attribute_name, item_attribute_value)
return item_attribute_value in (
[self.attribute_value] if isinstance(self.attribute_value, str) else self.attribute_value
)
Expand Down
32 changes: 31 additions & 1 deletion providers/amazon/tests/unit/amazon/aws/hooks/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import os
import re
from collections.abc import Iterator
from datetime import datetime as std_datetime, timezone
from datetime import datetime as std_datetime, timedelta, timezone
from pathlib import Path
from unittest import mock, mock as async_mock
from unittest.mock import AsyncMock, MagicMock, Mock, patch
Expand Down Expand Up @@ -1137,6 +1137,36 @@ async def test_s3_key_hook_is_keys_unchanged_exception_async(self, mock_list_key

assert response == {"message": "test_bucket/test between pokes.", "status": "error"}

@pytest.mark.asyncio
@mock.patch.object(S3Hook, "_list_keys_async", autospec=True)
async def test_s3_key_hook_is_keys_unchanged_success_async(self, mock_list_keys, time_machine):
frozen_dt = std_datetime(2026, 1, 1, 12, 0, 5, tzinfo=timezone.utc)
time_machine.move_to(frozen_dt, tick=False)
mock_list_keys.return_value = ["test"]

s3_hook_async = S3Hook()
mock_client = AsyncMock()

response = await s3_hook_async.is_keys_unchanged_async(
client=mock_client,
bucket_name="test_bucket",
prefix="test",
inactivity_period=3,
min_objects=1,
previous_objects={"test"},
inactivity_seconds=0,
allow_delete=False,
last_activity_time=frozen_dt - timedelta(seconds=5),
)

assert response == {
"status": "success",
"message": (
"SUCCESS: Sensor found 1 objects at test_bucket/test. "
"Waited at least 3 seconds, with no new objects uploaded."
),
}

@pytest.mark.asyncio
@async_mock.patch("airflow.providers.amazon.aws.triggers.s3.S3Hook._list_keys_async")
async def test_s3_key_hook_is_keys_unchanged_async_handle_tzinfo(self, mock_list_keys):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

from __future__ import annotations

from unittest import mock

from moto import mock_aws

from airflow.providers.amazon.aws.hooks.dynamodb import DynamoDBHook
Expand Down Expand Up @@ -187,8 +189,9 @@ def test_init(self):
assert sensor.hook._verify is None
assert sensor.hook._config is None

@mock.patch.object(DynamoDBValueSensor, "log")
@mock_aws
def test_sensor_with_pk(self):
def test_sensor_with_pk(self, mock_log):
hook = DynamoDBHook(table_name=self.table_name, table_keys=[self.pk_name])

hook.conn.create_table(
Expand All @@ -204,6 +207,7 @@ def test_sensor_with_pk(self):
hook.write_batch_data(items)

assert self.sensor_pk.poke(None)
mock_log.info.assert_any_call("Got: %s = %s", self.attribute_name, self.attribute_value[1])

@mock_aws
def test_sensor_with_pk_and_sk(self):
Expand Down