Skip to content

Commit

Permalink
Fix spell check
Browse files Browse the repository at this point in the history
  • Loading branch information
tnk-ysk committed Jan 18, 2025
1 parent 8e0b62c commit d235c1d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 22 deletions.
1 change: 1 addition & 0 deletions docs/spelling_wordlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,7 @@ traceback
tracebacks
tracemalloc
TrainingPipeline
TransferOperation
TranslationServiceClient
travis
triage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,7 @@ async def list_transfer_operations(
self,
request_filter: dict | None = None,
**kwargs,
) -> list[operations_pb2.Operation]:
) -> list[TransferOperation]:
"""
Get a transfer operation in Google Storage Transfer Service.
Expand Down Expand Up @@ -659,7 +659,11 @@ async def list_transfer_operations(
else None
)

return operations
transfer_operations = [
protobuf_helpers.from_any_pb(TransferOperation, op.metadata) for op in operations
]

return transfer_operations

async def _inject_project_id(self, body: dict, param_name: str, target_key: str) -> dict:
body = deepcopy(body)
Expand All @@ -673,7 +677,7 @@ async def _inject_project_id(self, body: dict, param_name: str, target_key: str)

@staticmethod
async def operations_contain_expected_statuses(
operations: list[operations_pb2.Operation], expected_statuses: set[str] | str
operations: list[TransferOperation], expected_statuses: set[str] | str
) -> bool:
"""
Check whether an operation exists with the expected status.
Expand All @@ -692,10 +696,7 @@ async def operations_contain_expected_statuses(
if not operations:
return False

current_statuses = {
protobuf_helpers.from_any_pb(TransferOperation, operation.metadata).status.name
for operation in operations
}
current_statuses = {operation.status.name for operation in operations}

if len(current_statuses - expected_statuses_set) != len(current_statuses):
return True
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,14 @@ async def test_get_last_operation_none(self, mock_deserialize, mock_conn, hook_a

@pytest.mark.asyncio
@mock.patch(f"{TRANSFER_HOOK_PATH}.CloudDataTransferServiceAsyncHook.get_conn")
async def test_list_transfer_operations(self, mock_conn, hook_async):
@mock.patch("google.api_core.protobuf_helpers.from_any_pb")
async def test_list_transfer_operations(self, from_any_pb, mock_conn, hook_async):
expected_operations = [mock.MagicMock(), mock.MagicMock()]
from_any_pb.side_effect = expected_operations

mock_conn.return_value.list_operations.side_effect = [
mock.MagicMock(next_page_token="token", operations=[expected_operations[0]]),
mock.MagicMock(next_page_token=None, operations=[expected_operations[1]]),
mock.MagicMock(next_page_token="token", operations=[mock.MagicMock()]),
mock.MagicMock(next_page_token=None, operations=[mock.MagicMock()]),
]

actual_operations = await hook_async.list_transfer_operations(
Expand All @@ -154,12 +157,8 @@ async def test_list_transfer_operations(self, mock_conn, hook_async):
),
],
)
@mock.patch("google.api_core.protobuf_helpers.from_any_pb")
async def test_operations_contain_expected_statuses_red_path(
self, from_any_pb, statuses, expected_statuses
):
operations = [mock.MagicMock() for _ in statuses]
from_any_pb.side_effect = [mock.MagicMock(**{"status.name": status}) for status in statuses]
async def test_operations_contain_expected_statuses_red_path(self, statuses, expected_statuses):
operations = [mock.MagicMock(**{"status.name": status}) for status in statuses]

with pytest.raises(
AirflowException,
Expand Down Expand Up @@ -193,12 +192,8 @@ async def test_operations_contain_expected_statuses_red_path(
),
],
)
@mock.patch("google.api_core.protobuf_helpers.from_any_pb")
async def test_operations_contain_expected_statuses_green_path(
self, from_any_pb, statuses, expected_statuses
):
operations = [mock.MagicMock() for _ in statuses]
from_any_pb.side_effect = [mock.MagicMock(**{"status.name": status}) for status in statuses]
async def test_operations_contain_expected_statuses_green_path(self, statuses, expected_statuses):
operations = [mock.MagicMock(**{"status.name": status}) for status in statuses]

result = await CloudDataTransferServiceAsyncHook.operations_contain_expected_statuses(
operations, expected_statuses
Expand Down

0 comments on commit d235c1d

Please sign in to comment.