Skip to content
Merged
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
6 changes: 3 additions & 3 deletions airflow/providers/microsoft/azure/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ def get_field(*, conn_id: str, conn_type: str, extras: dict, field_name: str):

def _get_default_azure_credential(
*,
managed_identity_client_id: str | None,
workload_identity_tenant_id: str | None,
managed_identity_client_id: str | None = None,
workload_identity_tenant_id: str | None = None,
use_async: bool = False,
) -> DefaultAzureCredential | AsyncDefaultAzureCredential:
"""Get DefaultAzureCredential based on provided arguments.
Expand Down Expand Up @@ -88,7 +88,7 @@ def _get_default_azure_credential(

get_async_default_azure_credential: partial[AsyncDefaultAzureCredential] = partial(
_get_default_azure_credential, # type: ignore[arg-type]
use_async=False,
use_async=True,
)


Expand Down
16 changes: 16 additions & 0 deletions tests/providers/microsoft/azure/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@
from airflow.providers.microsoft.azure.utils import (
AzureIdentityCredentialAdapter,
add_managed_identity_connection_widgets,
get_async_default_azure_credential,
get_field,
# _get_default_azure_credential
get_sync_default_azure_credential,
)

MODULE = "airflow.providers.microsoft.azure.utils"
Expand Down Expand Up @@ -77,6 +80,19 @@ def test_func() -> dict[str, Any]:
assert "workload_identity_tenant_id" in widgets


@mock.patch(f"{MODULE}.DefaultAzureCredential")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Lee-W, the changes look good. Do you think it is a good idea to elaborate the unit tests a bit by adding mock objects and running tests to compare expected vs. actual for the method calls?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure. I think the main point here is verifying we're calling the right object

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah - for me it's enough to check they are called. Too detailed tests are often problematic - especially in case of some auth methods that tend to change when client libraries change. We often have to fix such tests when new versions of libraries are released just to add a new parameter expected etc. So I'd say just "called" is good enough for me - especially that we have detailed test for the credentials class itself

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, @Lee-W and @potiuk, thanks for clarifying.

def test_get_sync_default_azure_credential(mock_default_azure_credential):
get_sync_default_azure_credential()

assert mock_default_azure_credential.called


@mock.patch(f"{MODULE}.AsyncDefaultAzureCredential")
def test_get_async_default_azure_credential(mock_default_azure_credential):
get_async_default_azure_credential()
assert mock_default_azure_credential.called


class TestAzureIdentityCredentialAdapter:
@mock.patch(f"{MODULE}.PipelineRequest")
@mock.patch(f"{MODULE}.BearerTokenCredentialPolicy")
Expand Down