Skip to content

Commit

Permalink
DynamoDBHook - waiter_path() to consider resource_type or `client_t…
Browse files Browse the repository at this point in the history
…ype` (#30595)

* Add  while initilizing

* Add  while initilizing

* Add logic to pick either client_type or resource_type

* Add test case

* Assert expected path
  • Loading branch information
utkarsharma2 authored Apr 14, 2023
1 parent cb5a2c5 commit 7c2d361
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion airflow/providers/amazon/aws/hooks/base_aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,8 @@ def test_connection(self):

@cached_property
def waiter_path(self) -> PathLike[str] | None:
path = Path(__file__).parents[1].joinpath(f"waiters/{self.client_type}.json").resolve()
filename = self.client_type if self.client_type else self.resource_type
path = Path(__file__).parents[1].joinpath(f"waiters/{filename}.json").resolve()
return path if path.exists() else None

def get_waiter(self, waiter_name: str, parameters: dict[str, str] | None = None) -> Waiter:
Expand Down
7 changes: 7 additions & 0 deletions tests/providers/amazon/aws/hooks/test_dynamodb.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import uuid
from unittest import mock

from moto import mock_dynamodb

Expand Down Expand Up @@ -55,3 +56,9 @@ def test_insert_batch_items_dynamodb_table(self):

table.meta.client.get_waiter("table_exists").wait(TableName="test_airflow")
assert table.item_count == 10

@mock.patch("pathlib.Path.exists", return_value=True)
def test_waiter_path_generated_from_resource_type(self, _):
hook = DynamoDBHook(aws_conn_id="aws_default")
path = hook.waiter_path
assert path.as_uri().endswith("/airflow/airflow/providers/amazon/aws/waiters/dynamodb.json")

0 comments on commit 7c2d361

Please sign in to comment.