|
2 | 2 | from unittest import mock
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from azure.keyvault.secrets.aio import SecretClient |
5 | 6 |
|
6 | 7 | import app
|
7 | 8 |
|
| 9 | +from .mocks import MockKeyVaultSecret |
| 10 | + |
8 | 11 |
|
9 | 12 | @pytest.fixture
|
10 | 13 | def minimal_env(monkeypatch):
|
@@ -105,3 +108,39 @@ async def test_app_config_for_client(client):
|
105 | 108 | assert result["showGPT4VOptions"] == (os.getenv("USE_GPT4V") == "true")
|
106 | 109 | assert result["showSemanticRankerOption"] is True
|
107 | 110 | assert result["showVectorOption"] is True
|
| 111 | + |
| 112 | + |
| 113 | +@pytest.mark.asyncio |
| 114 | +async def test_app_visionkey_notfound(monkeypatch, minimal_env): |
| 115 | + monkeypatch.setenv("AZURE_KEY_VAULT_NAME", "my_key_vault") |
| 116 | + monkeypatch.setenv("VISION_SECRET_NAME", "") |
| 117 | + monkeypatch.setenv("SEARCH_SECRET_NAME", "search-secret-name") |
| 118 | + |
| 119 | + async def get_secret(*args, **kwargs): |
| 120 | + if args[1] == "vision-secret-name": |
| 121 | + raise Exception("Key not found") |
| 122 | + return MockKeyVaultSecret("mysecret") |
| 123 | + |
| 124 | + monkeypatch.setattr(SecretClient, "get_secret", get_secret) |
| 125 | + |
| 126 | + quart_app = app.create_app() |
| 127 | + async with quart_app.test_app() as test_app: |
| 128 | + test_app.test_client() |
| 129 | + |
| 130 | + |
| 131 | +@pytest.mark.asyncio |
| 132 | +async def test_app_searchkey_notfound(monkeypatch, minimal_env): |
| 133 | + monkeypatch.setenv("AZURE_KEY_VAULT_NAME", "my_key_vault") |
| 134 | + monkeypatch.setenv("VISION_SECRET_NAME", "vision-secret-name") |
| 135 | + monkeypatch.setenv("SEARCH_SECRET_NAME", "") |
| 136 | + |
| 137 | + async def get_secret(*args, **kwargs): |
| 138 | + if args[1] == "search-secret-name": |
| 139 | + raise Exception("Key not found") |
| 140 | + return MockKeyVaultSecret("mysecret") |
| 141 | + |
| 142 | + monkeypatch.setattr(SecretClient, "get_secret", get_secret) |
| 143 | + |
| 144 | + quart_app = app.create_app() |
| 145 | + async with quart_app.test_app() as test_app: |
| 146 | + test_app.test_client() |
0 commit comments