Skip to content

Commit

Permalink
Account for vision key only situation (#1192)
Browse files Browse the repository at this point in the history
  • Loading branch information
pamelafox authored Jan 26, 2024
1 parent 8048b28 commit 2e900be
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
4 changes: 2 additions & 2 deletions app/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ async def setup_clients():
key_vault_client = SecretClient(
vault_url=f"https://{AZURE_KEY_VAULT_NAME}.vault.azure.net", credential=azure_credential
)
vision_key = (await key_vault_client.get_secret(VISION_SECRET_NAME)).value
search_key = (await key_vault_client.get_secret(SEARCH_SECRET_NAME)).value
vision_key = VISION_SECRET_NAME and (await key_vault_client.get_secret(VISION_SECRET_NAME)).value
search_key = SEARCH_SECRET_NAME and (await key_vault_client.get_secret(SEARCH_SECRET_NAME)).value
await key_vault_client.close()

# Set up clients for AI Search and Storage
Expand Down
39 changes: 39 additions & 0 deletions tests/test_app_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
from unittest import mock

import pytest
from azure.keyvault.secrets.aio import SecretClient

import app

from .mocks import MockKeyVaultSecret


@pytest.fixture
def minimal_env(monkeypatch):
Expand Down Expand Up @@ -105,3 +108,39 @@ async def test_app_config_for_client(client):
assert result["showGPT4VOptions"] == (os.getenv("USE_GPT4V") == "true")
assert result["showSemanticRankerOption"] is True
assert result["showVectorOption"] is True


@pytest.mark.asyncio
async def test_app_visionkey_notfound(monkeypatch, minimal_env):
monkeypatch.setenv("AZURE_KEY_VAULT_NAME", "my_key_vault")
monkeypatch.setenv("VISION_SECRET_NAME", "")
monkeypatch.setenv("SEARCH_SECRET_NAME", "search-secret-name")

async def get_secret(*args, **kwargs):
if args[1] == "vision-secret-name":
raise Exception("Key not found")
return MockKeyVaultSecret("mysecret")

monkeypatch.setattr(SecretClient, "get_secret", get_secret)

quart_app = app.create_app()
async with quart_app.test_app() as test_app:
test_app.test_client()


@pytest.mark.asyncio
async def test_app_searchkey_notfound(monkeypatch, minimal_env):
monkeypatch.setenv("AZURE_KEY_VAULT_NAME", "my_key_vault")
monkeypatch.setenv("VISION_SECRET_NAME", "vision-secret-name")
monkeypatch.setenv("SEARCH_SECRET_NAME", "")

async def get_secret(*args, **kwargs):
if args[1] == "search-secret-name":
raise Exception("Key not found")
return MockKeyVaultSecret("mysecret")

monkeypatch.setattr(SecretClient, "get_secret", get_secret)

quart_app = app.create_app()
async with quart_app.test_app() as test_app:
test_app.test_client()

0 comments on commit 2e900be

Please sign in to comment.