Skip to content

Commit e6f85f9

Browse files
committed
more tests
1 parent 212d3cf commit e6f85f9

File tree

5 files changed

+435
-0
lines changed

5 files changed

+435
-0
lines changed

tests/conftest.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ async def mock_search(self, *args, **kwargs):
6161

6262

6363
async def mock_retrieve(self, *args, **kwargs):
64+
retrieval_request = kwargs.get("retrieval_request")
65+
assert retrieval_request is not None
66+
assert retrieval_request.target_index_params is not None
67+
assert len(retrieval_request.target_index_params) == 1
68+
self.filter = retrieval_request.target_index_params[0].filter_add_on
6469
return mock_retrieval_response()
6570

6671

@@ -377,6 +382,24 @@ def mock_blob_container_client(monkeypatch):
377382
}
378383
]
379384

385+
agent_auth_envs = [
386+
{
387+
"OPENAI_HOST": "azure",
388+
"AZURE_OPENAI_SERVICE": "test-openai-service",
389+
"AZURE_OPENAI_CHATGPT_MODEL": "gpt-4o-mini",
390+
"AZURE_OPENAI_CHATGPT_DEPLOYMENT": "gpt-4o-mini",
391+
"AZURE_OPENAI_EMB_DEPLOYMENT": "test-ada",
392+
"AZURE_OPENAI_SEARCHAGENT_MODEL": "gpt-4o-mini",
393+
"AZURE_OPENAI_SEARCHAGENT_DEPLOYMENT": "gpt-4o-mini",
394+
"USE_AGENTIC_RETRIEVAL": "true",
395+
"AZURE_USE_AUTHENTICATION": "true",
396+
"AZURE_SERVER_APP_ID": "SERVER_APP",
397+
"AZURE_SERVER_APP_SECRET": "SECRET",
398+
"AZURE_CLIENT_APP_ID": "CLIENT_APP",
399+
"AZURE_TENANT_ID": "TENANT_ID",
400+
}
401+
]
402+
380403

381404
@pytest.fixture(params=envs, ids=["client0", "client1"])
382405
def mock_env(monkeypatch, request):
@@ -450,6 +473,29 @@ def mock_agent_env(monkeypatch, request):
450473
mock_default_azure_credential.return_value = MockAzureCredential()
451474
yield
452475

476+
@pytest.fixture(params=agent_auth_envs, ids=["agent_auth_client0"])
477+
def mock_agent_auth_env(monkeypatch, request):
478+
with mock.patch.dict(os.environ, clear=True):
479+
monkeypatch.setenv("AZURE_STORAGE_ACCOUNT", "test-storage-account")
480+
monkeypatch.setenv("AZURE_STORAGE_CONTAINER", "test-storage-container")
481+
monkeypatch.setenv("AZURE_STORAGE_RESOURCE_GROUP", "test-storage-rg")
482+
monkeypatch.setenv("AZURE_SUBSCRIPTION_ID", "test-storage-subid")
483+
monkeypatch.setenv("ENABLE_LANGUAGE_PICKER", "true")
484+
monkeypatch.setenv("USE_SPEECH_INPUT_BROWSER", "true")
485+
monkeypatch.setenv("USE_SPEECH_OUTPUT_AZURE", "true")
486+
monkeypatch.setenv("AZURE_SEARCH_INDEX", "test-search-index")
487+
monkeypatch.setenv("AZURE_SEARCH_AGENT", "test-search-agent")
488+
monkeypatch.setenv("AZURE_SEARCH_SERVICE", "test-search-service")
489+
monkeypatch.setenv("AZURE_SPEECH_SERVICE_ID", "test-id")
490+
monkeypatch.setenv("AZURE_SPEECH_SERVICE_LOCATION", "eastus")
491+
monkeypatch.setenv("ALLOWED_ORIGIN", "https://frontend.com")
492+
for key, value in request.param.items():
493+
monkeypatch.setenv(key, value)
494+
495+
with mock.patch("app.AzureDeveloperCliCredential") as mock_default_azure_credential:
496+
mock_default_azure_credential.return_value = MockAzureCredential()
497+
yield
498+
453499
@pytest_asyncio.fixture(scope="function")
454500
async def client(
455501
monkeypatch,
@@ -506,6 +552,31 @@ async def agent_client(
506552
mock_openai_embedding(test_app.app.config[app.CONFIG_OPENAI_CLIENT])
507553
yield test_app.test_client()
508554

555+
@pytest_asyncio.fixture(scope="function")
556+
async def agent_auth_client(
557+
monkeypatch,
558+
mock_agent_auth_env,
559+
mock_openai_chatcompletion,
560+
mock_openai_embedding,
561+
mock_acs_search,
562+
mock_acs_agent,
563+
mock_blob_container_client,
564+
mock_azurehttp_calls,
565+
mock_confidential_client_success,
566+
mock_validate_token_success,
567+
mock_list_groups_success,
568+
):
569+
quart_app = app.create_app()
570+
571+
async with quart_app.test_app() as test_app:
572+
test_app.app.config.update({"TESTING": True})
573+
mock_openai_chatcompletion(test_app.app.config[app.CONFIG_OPENAI_CLIENT])
574+
mock_openai_embedding(test_app.app.config[app.CONFIG_OPENAI_CLIENT])
575+
client = test_app.test_client()
576+
client.config = quart_app.config
577+
578+
yield client
579+
509580

510581
@pytest_asyncio.fixture(scope="function")
511582
async def client_with_expiring_token(
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"context": {
3+
"data_points": {
4+
"images": null,
5+
"text": [
6+
"Benefit_Options-2.pdf: There is a whistleblower policy."
7+
]
8+
},
9+
"followup_questions": null,
10+
"thoughts": [
11+
{
12+
"description": [
13+
{
14+
"content": "What is the capital of France?",
15+
"role": "user"
16+
}
17+
],
18+
"props": {
19+
"filter": "category ne 'excluded' and (oids/any(g:search.in(g, 'OID_X')) or groups/any(g:search.in(g, 'GROUP_Y, GROUP_Z')))",
20+
"max_docs_for_reranker": 150,
21+
"reranker_threshold": 0
22+
},
23+
"title": "Use agentic retrieval"
24+
},
25+
{
26+
"description": [
27+
{
28+
"captions": [],
29+
"category": null,
30+
"content": "There is a whistleblower policy.",
31+
"groups": null,
32+
"id": "Benefit_Options-2.pdf",
33+
"oids": null,
34+
"reranker_score": null,
35+
"score": null,
36+
"search_agent_query": "whistleblower query",
37+
"sourcefile": null,
38+
"sourcepage": "Benefit_Options-2.pdf"
39+
}
40+
],
41+
"props": {
42+
"deployment": "gpt-4o-mini",
43+
"model": "gpt-4o-mini",
44+
"query_plan": [
45+
{
46+
"elapsed_ms": 200,
47+
"id": 0,
48+
"input_tokens": 10,
49+
"output_tokens": 20,
50+
"type": "ModelQueryPlanning"
51+
},
52+
{
53+
"count": 10,
54+
"elapsed_ms": 50,
55+
"id": 1,
56+
"query": {
57+
"search": "whistleblower query"
58+
},
59+
"target_index": "index",
60+
"type": "AzureSearchQuery"
61+
}
62+
]
63+
},
64+
"title": "Agentic retrieval results (top 3)"
65+
},
66+
{
67+
"description": [
68+
{
69+
"content": "You are an intelligent assistant helping Contoso Inc employees with their healthcare plan questions and employee handbook questions.\nUse 'you' to refer to the individual asking the questions even if they ask with 'I'.\nAnswer the following question using only the data provided in the sources below.\nEach source has a name followed by colon and the actual information, always include the source name for each fact you use in the response.\nIf you cannot answer using the sources below, say you don't know. Use below example to answer",
70+
"role": "system"
71+
},
72+
{
73+
"content": "What is the deductible for the employee plan for a visit to Overlake in Bellevue?\n\nSources:\ninfo1.txt: deductibles depend on whether you are in-network or out-of-network. In-network deductibles are $500 for employee and $1000 for family. Out-of-network deductibles are $1000 for employee and $2000 for family.\ninfo2.pdf: Overlake is in-network for the employee plan.\ninfo3.pdf: Overlake is the name of the area that includes a park and ride near Bellevue.\ninfo4.pdf: In-network institutions include Overlake, Swedish and others in the region.",
74+
"role": "user"
75+
},
76+
{
77+
"content": "In-network deductibles are $500 for employee and $1000 for family [info1.txt] and Overlake is in-network for the employee plan [info2.pdf][info4.pdf].",
78+
"role": "assistant"
79+
},
80+
{
81+
"content": "What is the capital of France?\nSources:\n\nBenefit_Options-2.pdf: There is a whistleblower policy.",
82+
"role": "user"
83+
}
84+
],
85+
"props": {
86+
"deployment": "gpt-4o-mini",
87+
"model": "gpt-4o-mini",
88+
"token_usage": {
89+
"completion_tokens": 896,
90+
"prompt_tokens": 23,
91+
"reasoning_tokens": 0,
92+
"total_tokens": 919
93+
}
94+
},
95+
"title": "Prompt to generate answer"
96+
}
97+
]
98+
},
99+
"message": {
100+
"content": "The capital of France is Paris. [Benefit_Options-2.pdf].",
101+
"role": "assistant"
102+
},
103+
"session_state": null
104+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"context": {
3+
"data_points": {
4+
"images": null,
5+
"text": [
6+
"Benefit_Options-2.pdf: There is a whistleblower policy."
7+
]
8+
},
9+
"followup_questions": null,
10+
"thoughts": [
11+
{
12+
"description": [
13+
{
14+
"content": "What is the capital of France?",
15+
"role": "user"
16+
}
17+
],
18+
"props": {
19+
"filter": null,
20+
"max_docs_for_reranker": 150,
21+
"reranker_threshold": 0
22+
},
23+
"title": "Use agentic retrieval"
24+
},
25+
{
26+
"description": [
27+
{
28+
"captions": [],
29+
"category": null,
30+
"content": "There is a whistleblower policy.",
31+
"groups": null,
32+
"id": "Benefit_Options-2.pdf",
33+
"oids": null,
34+
"reranker_score": null,
35+
"score": null,
36+
"search_agent_query": "whistleblower query",
37+
"sourcefile": null,
38+
"sourcepage": "Benefit_Options-2.pdf"
39+
}
40+
],
41+
"props": {
42+
"deployment": "gpt-4o-mini",
43+
"model": "gpt-4o-mini",
44+
"query_plan": [
45+
{
46+
"elapsed_ms": 200,
47+
"id": 0,
48+
"input_tokens": 10,
49+
"output_tokens": 20,
50+
"type": "ModelQueryPlanning"
51+
},
52+
{
53+
"count": 10,
54+
"elapsed_ms": 50,
55+
"id": 1,
56+
"query": {
57+
"search": "whistleblower query"
58+
},
59+
"target_index": "index",
60+
"type": "AzureSearchQuery"
61+
}
62+
]
63+
},
64+
"title": "Agentic retrieval results (top 3)"
65+
},
66+
{
67+
"description": [
68+
{
69+
"content": "Assistant helps the company employees with their healthcare plan questions, and questions about the employee handbook. Be brief in your answers.\nAnswer ONLY with the facts listed in the list of sources below. If there isn't enough information below, say you don't know. Do not generate answers that don't use the sources below. If asking a clarifying question to the user would help, ask the question.\nIf the question is not in English, answer in the language used in the question.\nEach source has a name followed by colon and the actual information, always include the source name for each fact you use in the response. Use square brackets to reference the source, for example [info1.txt]. Don't combine sources, list each source separately, for example [info1.txt][info2.pdf].",
70+
"role": "system"
71+
},
72+
{
73+
"content": "What is the capital of France?\n\nSources:\n\nBenefit_Options-2.pdf: There is a whistleblower policy.",
74+
"role": "user"
75+
}
76+
],
77+
"props": {
78+
"deployment": "gpt-4o-mini",
79+
"model": "gpt-4o-mini",
80+
"token_usage": {
81+
"completion_tokens": 896,
82+
"prompt_tokens": 23,
83+
"reasoning_tokens": 0,
84+
"total_tokens": 919
85+
}
86+
},
87+
"title": "Prompt to generate answer"
88+
}
89+
]
90+
},
91+
"message": {
92+
"content": "The capital of France is Paris. [Benefit_Options-2.pdf].",
93+
"role": "assistant"
94+
},
95+
"session_state": null
96+
}

0 commit comments

Comments
 (0)