Skip to content

Commit 27f3465

Browse files
Research assistant unit test pylint correction
1 parent a1082d8 commit 27f3465

File tree

1 file changed

+14
-25
lines changed

1 file changed

+14
-25
lines changed

ResearchAssistant/App/test_app.py

+14-25
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
import json
22
import os
33
from unittest.mock import MagicMock, Mock, patch
4-
from flask import Flask, request
4+
from flask import Flask
55
import pytest
6-
import requests
76
import urllib
87

9-
from app import (extract_value, fetchUserGroups, format_as_ndjson,
8+
from app import (extract_value, fetchUserGroups,
109
formatApiResponseNoStreaming, formatApiResponseStreaming,
1110
generateFilterString, is_chat_model, parse_multi_columns,
1211
prepare_body_headers_with_data, should_use_data,
13-
stream_with_data, conversation_with_data, draft_document_generate)
12+
stream_with_data, draft_document_generate)
1413

1514
AZURE_SEARCH_SERVICE = os.environ.get("AZURE_SEARCH_SERVICE", "")
1615
AZURE_OPENAI_KEY = os.environ.get("AZURE_OPENAI_KEY", "")
1716
AZURE_SEARCH_PERMITTED_GROUPS_COLUMN = os.environ.get(
1817
"AZURE_SEARCH_PERMITTED_GROUPS_COLUMN", ""
1918
)
2019

20+
2121
def test_parse_multi_columns():
2222
assert parse_multi_columns("a|b|c") == ["a", "b", "c"]
2323
assert parse_multi_columns("a,b,c") == ["a", "b", "c"]
@@ -160,9 +160,9 @@ def test_generateFilterString(mock_fetchUserGroups):
160160
userToken = "fake_token"
161161

162162
filter_string = generateFilterString(userToken)
163-
print("filter string",filter_string)
164163
assert filter_string == "None/any(g:search.in(g, '1, 2'))"
165164

165+
166166
def test_prepare_body_headers_with_data():
167167
# Create a mock request
168168
mock_request = MagicMock()
@@ -208,19 +208,6 @@ def test_prepare_body_headers_with_data():
208208
assert headers["x-ms-useragent"] == "GitHubSampleWebApp/PublicAPI/3.0.0"
209209

210210

211-
def test_invalid_datasource_type():
212-
mock_request = MagicMock()
213-
mock_request.json = {"messages": ["Hello, world!"], "index_name": "grants"}
214-
215-
216-
with patch("app.DATASOURCE_TYPE", "InvalidType"):
217-
with pytest.raises(Exception) as exc_info:
218-
prepare_body_headers_with_data(mock_request)
219-
assert "DATASOURCE_TYPE is not configured or unknown: InvalidType" in str(
220-
exc_info.value
221-
)
222-
223-
224211
def test_invalid_datasource_type():
225212
mock_request = MagicMock()
226213
mock_request.json = {"messages": ["Hello, world!"], "index_name": "grants"}
@@ -318,16 +305,16 @@ def test_stream_with_data_azure_success():
318305
print(results, "result test case")
319306
assert len(results) == 1
320307

308+
321309
# Mock constants
322310
USE_AZURE_AI_STUDIO = "true"
323311
AZURE_OPENAI_PREVIEW_API_VERSION = "2023-06-01-preview"
324312
DEBUG_LOGGING = False
325-
326313
AZURE_SEARCH_SERVICE = os.environ.get("AZURE_SEARCH_SERVICE", "mysearchservice")
327314

328315

329316
def test_stream_with_data_azure_error():
330-
317+
331318
body = {
332319
"messages": [
333320
{
@@ -380,10 +367,9 @@ def test_stream_with_data_azure_error():
380367
}
381368
],
382369
}
383-
370+
384371
if USE_AZURE_AI_STUDIO.lower() == "true":
385-
body = body
386-
372+
body = body
387373
headers = {
388374
"Content-Type": "application/json",
389375
"api-key": "",
@@ -410,6 +396,7 @@ def test_stream_with_data_azure_error():
410396
print(results, "result test case")
411397
assert len(results) == 1
412398

399+
413400
def test_formatApiResponseNoStreaming():
414401
rawResponse = {
415402
"id": "1",
@@ -463,6 +450,8 @@ def test_extract_value():
463450
assert extract_value("unknown", text) == "N/A"
464451

465452
app = Flask(__name__)
453+
454+
466455
app.add_url_rule("/draft_document/generate_section", "draft_document_generate", draft_document_generate, methods=["POST"])
467456

468457

@@ -541,13 +530,15 @@ def test_draft_document_generate_with_context(mock_os_environ, mock_urlopen, cli
541530
assert "content" in response_json
542531
assert response_json["content"] == "Generated content with context."
543532

533+
544534
@pytest.fixture
545535
def clients():
546536
app = Flask(__name__)
547537
app.route('/draft_document/generate_section', methods=['POST'])(draft_document_generate)
548538
client = app.test_client()
549539
yield client
550540

541+
551542
@patch("urllib.request.urlopen")
552543
@patch("os.environ.get")
553544
def test_draft_document_generate_http_error(mock_env_get, mock_urlopen, client):
@@ -582,5 +573,3 @@ def test_draft_document_generate_http_error(mock_env_get, mock_urlopen, client):
582573
)
583574

584575
assert response.status_code == 200
585-
586-

0 commit comments

Comments
 (0)