66from azure .search .documents .indexes ._generated .models import (
77 NativeBlobSoftDeleteDeletionDetectionPolicy ,
88)
9+ from azure .search .documents .indexes .models import (
10+ SearchIndexerDataUserAssignedIdentity ,
11+ )
912
1013AZURE_AUTH_TYPE = "keys"
1114AZURE_SEARCH_KEY = "mock-key"
1821AZURE_BLOB_ACCOUNT_KEY = "mock-key"
1922AZURE_SUBSCRIPTION_ID = "mock-subscriptionid"
2023AZURE_RESOURCE_GROUP = "mock-resource-group"
24+ AZURE_BLOB_CONTAINER_NAME = "mock-container-name"
25+ MANAGED_IDENTITY_RESOURCE_ID = "/subscriptions/mock-sub/resourceGroups/mock-rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mock-identity"
2126
2227
2328@pytest .fixture (autouse = True )
@@ -33,6 +38,13 @@ def env_helper_mock():
3338 env_helper .AZURE_OPENAI_ENDPOINT = AZURE_OPENAI_ENDPOINT
3439 env_helper .AZURE_OPENAI_EMBEDDING_MODEL = AZURE_OPENAI_EMBEDDING_MODEL
3540 env_helper .AZURE_SEARCH_DATASOURCE_NAME = AZURE_SEARCH_DATASOURCE_NAME
41+ env_helper .AZURE_BLOB_ACCOUNT_NAME = AZURE_BLOB_ACCOUNT_NAME
42+ env_helper .AZURE_BLOB_ACCOUNT_KEY = AZURE_BLOB_ACCOUNT_KEY
43+ env_helper .AZURE_SUBSCRIPTION_ID = AZURE_SUBSCRIPTION_ID
44+ env_helper .AZURE_RESOURCE_GROUP = AZURE_RESOURCE_GROUP
45+ env_helper .AZURE_BLOB_CONTAINER_NAME = AZURE_BLOB_CONTAINER_NAME
46+ env_helper .MANAGED_IDENTITY_RESOURCE_ID = MANAGED_IDENTITY_RESOURCE_ID
47+ env_helper .APP_ENV = "prod"
3648
3749 yield env_helper
3850
@@ -89,6 +101,9 @@ def test_create_or_update_datasource_keys(
89101 connection_string = keys_datasource_connection ,
90102 container = search_indexer_data_container_mock .return_value ,
91103 data_deletion_detection_policy = NativeBlobSoftDeleteDeletionDetectionPolicy (),
104+ identity = SearchIndexerDataUserAssignedIdentity (
105+ user_assigned_identity = env_helper_mock .MANAGED_IDENTITY_RESOURCE_ID
106+ ),
92107 )
93108
94109
@@ -123,4 +138,43 @@ def test_create_or_update_datasource_rbac(
123138 connection_string = rbac_datasource_connection ,
124139 container = search_indexer_data_container_mock .return_value ,
125140 data_deletion_detection_policy = NativeBlobSoftDeleteDeletionDetectionPolicy (),
141+ identity = SearchIndexerDataUserAssignedIdentity (
142+ user_assigned_identity = env_helper_mock .MANAGED_IDENTITY_RESOURCE_ID
143+ ),
144+ )
145+
146+
147+ def test_create_or_update_datasource_dev_environment (
148+ search_indexer_client_mock : MagicMock ,
149+ search_indexer_data_container_mock : MagicMock ,
150+ env_helper_mock : MagicMock ,
151+ search_indexer_datasource_connection_mock : MagicMock ,
152+ ):
153+ # given
154+ env_helper_mock .is_auth_type_keys .return_value = False
155+ env_helper_mock .AZURE_AUTH_TYPE = "rbac"
156+ env_helper_mock .APP_ENV = "dev" # Override for dev environment
157+ rbac_datasource_connection = f"ResourceId=/subscriptions/{ env_helper_mock .AZURE_SUBSCRIPTION_ID } /resourceGroups/{ env_helper_mock .AZURE_RESOURCE_GROUP } /providers/Microsoft.Storage/storageAccounts/{ env_helper_mock .AZURE_BLOB_ACCOUNT_NAME } /;"
158+
159+ azure_search_iv_datasource_helper = AzureSearchDatasource (env_helper_mock )
160+
161+ # when
162+ azure_search_iv_datasource_helper .create_or_update_datasource ()
163+
164+ # then
165+
166+ assert (
167+ azure_search_iv_datasource_helper .indexer_client
168+ == search_indexer_client_mock .return_value
169+ )
170+ search_indexer_data_container_mock .assert_called_once_with (
171+ name = env_helper_mock .AZURE_BLOB_CONTAINER_NAME
172+ )
173+ search_indexer_datasource_connection_mock .assert_called_once_with (
174+ name = env_helper_mock .AZURE_SEARCH_DATASOURCE_NAME ,
175+ type = "azureblob" ,
176+ connection_string = rbac_datasource_connection ,
177+ container = search_indexer_data_container_mock .return_value ,
178+ data_deletion_detection_policy = NativeBlobSoftDeleteDeletionDetectionPolicy (),
179+ identity = None ,
126180 )
0 commit comments