Skip to content

Commit f39cfab

Browse files
fix: Update SSL parameter to boolean in Postgres connection and add identity fields in Azure Search datasource tests
1 parent 19da326 commit f39cfab

File tree

6 files changed

+68
-4
lines changed

6 files changed

+68
-4
lines changed

code/tests/chat_history/test_postgresdbservice.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ async def test_connect(mock_credential, mock_connect, postgres_client, mock_conn
3939
database="test_db",
4040
password="mock_token",
4141
port=5432,
42-
ssl="require",
42+
ssl=True,
4343
)
4444
assert postgres_client.conn == mock_connection
4545

code/tests/functional/tests/functions/integrated_vectorization/test_integrated_vectorization_resource_creation.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ def test_integrated_vectorization_datasouce_created(
102102
"container": {
103103
"name": f"{app_config.get_from_json('AZURE_BLOB_STORAGE_INFO','containerName')}"
104104
},
105+
"identity": {
106+
"@odata.type": "#Microsoft.Azure.Search.DataUserAssignedIdentity",
107+
"userAssignedIdentity": ""
108+
},
105109
"dataDeletionDetectionPolicy": {
106110
"@odata.type": "#Microsoft.Azure.Search.NativeBlobSoftDeleteDeletionDetectionPolicy"
107111
},
@@ -367,6 +371,10 @@ def test_integrated_vectorization_skillset_created(
367371
"resourceUri": f"https://localhost:{httpserver.port}/",
368372
"deploymentId": f"{app_config.get_from_json('AZURE_OPENAI_EMBEDDING_MODEL_INFO','model')}",
369373
"apiKey": f"{app_config.get('AZURE_OPENAI_API_KEY')}",
374+
"authIdentity": {
375+
"@odata.type": "#Microsoft.Azure.Search.DataUserAssignedIdentity",
376+
"userAssignedIdentity": ""
377+
},
370378
},
371379
],
372380
"indexProjections": {

code/tests/utilities/helpers/test_azure_postgres_helper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_create_search_client_success(self, mock_connect, mock_credential):
3030
"https://ossrdbms-aad.database.windows.net/.default"
3131
)
3232
mock_connect.assert_called_once_with(
33-
"host=mock_host user=mock_user dbname=mock_database password=mock-access-token"
33+
"host=mock_host user=mock_user dbname=mock_database password=mock-access-token sslmode=require"
3434
)
3535

3636
@patch("backend.batch.utilities.helpers.azure_postgres_helper.psycopg2.connect")
@@ -92,7 +92,7 @@ def test_get_vector_store_success(self, mock_cursor, mock_connect, mock_credenti
9292
# Assert
9393
self.assertEqual(results, mock_results)
9494
mock_connect.assert_called_once_with(
95-
"host=mock_host user=mock_user dbname=mock_database password=mock-access-token"
95+
"host=mock_host user=mock_user dbname=mock_database password=mock-access-token sslmode=require"
9696
)
9797

9898
@patch("backend.batch.utilities.helpers.azure_postgres_helper.get_azure_credential")

code/tests/utilities/helpers/test_azure_search_helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ def env_helper_mock():
9090
env_helper.AZURE_SEARCH_CONVERSATIONS_LOG_INDEX = (
9191
AZURE_SEARCH_CONVERSATIONS_LOG_INDEX
9292
)
93+
env_helper.MANAGED_IDENTITY_CLIENT_ID = "mock-client-id"
9394

9495
env_helper.USE_ADVANCED_IMAGE_PROCESSING = USE_ADVANCED_IMAGE_PROCESSING
9596
env_helper.is_auth_type_keys.return_value = True
@@ -156,7 +157,7 @@ def test_creates_search_clients_with_rabc(
156157
AzureSearchHelper()
157158

158159
# then
159-
default_azure_credential_mock.assert_called_once_with()
160+
default_azure_credential_mock.assert_called_once_with("mock-client-id")
160161
search_client_mock.assert_called_once_with(
161162
endpoint=AZURE_SEARCH_SERVICE,
162163
index_name=AZURE_SEARCH_INDEX,

code/tests/utilities/helpers/test_secret_helper.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def test_get_secret_returns_value_from_secret_client_when_use_key_vault_is_true(
2525
secret_name = "MY_SECRET"
2626
expected_value = ""
2727
monkeypatch.setenv("USE_KEY_VAULT", "true")
28+
monkeypatch.setenv("AZURE_KEY_VAULT_ENDPOINT", "https://test-vault.vault.azure.net/")
2829
secret_client.return_value.get_secret.return_value.value = expected_value
2930
secret_helper = SecretHelper()
3031

code/tests/utilities/integrated_vectorization/test_azure_search_datasource.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
from azure.search.documents.indexes._generated.models import (
77
NativeBlobSoftDeleteDeletionDetectionPolicy,
88
)
9+
from azure.search.documents.indexes.models import (
10+
SearchIndexerDataUserAssignedIdentity,
11+
)
912

1013
AZURE_AUTH_TYPE = "keys"
1114
AZURE_SEARCH_KEY = "mock-key"
@@ -18,6 +21,8 @@
1821
AZURE_BLOB_ACCOUNT_KEY = "mock-key"
1922
AZURE_SUBSCRIPTION_ID = "mock-subscriptionid"
2023
AZURE_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

Comments
 (0)