Skip to content

Commit

Permalink
fix unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
AjitPadhi-Microsoft committed Sep 2, 2024
1 parent 0ebc56e commit d556854
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import re
import pytest
from pytest_httpserver import HTTPServer
from unittest.mock import ANY, MagicMock, patch
import requests

from tests.request_matching import (
Expand Down Expand Up @@ -175,9 +176,16 @@ def test_post_makes_correct_calls_to_openai_embeddings_to_embed_question_to_sear
)


@patch(
"backend.batch.utilities.helpers.config.config_helper.ConfigHelper.get_active_config_or_default"
)
def test_post_makes_correct_calls_to_openai_embeddings_to_embed_question_to_store_in_conversation_log(
app_url: str, app_config: AppConfig, httpserver: HTTPServer
get_active_config_or_default_mock,
app_url: str,
app_config: AppConfig,
httpserver: HTTPServer,
):
get_active_config_or_default_mock.prompts.conversational_flow = "custom"
# when
requests.post(f"{app_url}{path}", json=body)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import pytest
from pytest_httpserver import HTTPServer
from unittest.mock import patch
import requests
from string import Template

Expand Down Expand Up @@ -46,9 +47,18 @@ def setup_default_mocking(httpserver: HTTPServer, app_config: AppConfig):
httpserver.check()


@patch(
"backend.batch.utilities.helpers.config.config_helper.ConfigHelper.get_active_config_or_default"
)
def test_azure_byod_responds_successfully_when_streaming(
app_url: str, app_config: AppConfig, httpserver: HTTPServer
app_url: str,
app_config: AppConfig,
httpserver: HTTPServer,
get_active_config_or_default_mock,
):
get_active_config_or_default_mock.return_value.prompts.return_value = {
"conversational_flow": "byod"
}
# when
response = requests.post(f"{app_url}{path}", json=body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from pytest_httpserver import HTTPServer
import requests
from string import Template
from unittest.mock import patch, MagicMock

from tests.request_matching import (
RequestMatcher,
Expand Down Expand Up @@ -48,9 +49,28 @@ def setup_default_mocking(httpserver: HTTPServer, app_config: AppConfig):
httpserver.check()


@pytest.fixture(autouse=True)
def env_helper_mock():
with patch("backend.batch.utilities.helpers.env_helper.EnvHelper") as mock:
env_helper = mock.return_value

yield env_helper


@patch(
"backend.batch.utilities.helpers.config.config_helper.ConfigHelper.get_active_config_or_default"
)
def test_azure_byod_responds_successfully_when_streaming(
app_url: str, app_config: AppConfig, httpserver: HTTPServer
get_active_config_or_default_mock,
app_url: str,
app_config: AppConfig,
env_helper_mock: MagicMock,
):
# given
env_helper_mock.AZURE_SEARCH_KEY = None
env_helper_mock.should_use_data.return_value = False
get_active_config_or_default_mock.return_value.prompts.conversational_flow = "byod"

# when
response = requests.post(f"{app_url}{path}", json=body)

Expand Down Expand Up @@ -80,9 +100,18 @@ def test_azure_byod_responds_successfully_when_streaming(
}


@patch(
"backend.batch.utilities.helpers.config.config_helper.ConfigHelper.get_active_config_or_default"
)
def test_post_makes_correct_call_to_azure_openai(
app_url: str, app_config: AppConfig, httpserver: HTTPServer
get_active_config_or_default_mock,
app_url: str,
app_config: AppConfig,
httpserver: HTTPServer,
):
# given
get_active_config_or_default_mock.return_value.prompts.conversational_flow = "byod"

# when
requests.post(f"{app_url}{path}", json=body)

Expand Down
3 changes: 2 additions & 1 deletion code/tests/utilities/helpers/test_config_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ def config_dict():
"post_answering_prompt": "mock_post_answering_prompt",
"enable_post_answering_prompt": False,
"enable_content_safety": True,
"ai_assistant_type": "default"
"ai_assistant_type": "default",
"conversational_flow": "custom",
},
"messages": {
"post_answering_filter": "mock_post_answering_filter",
Expand Down

0 comments on commit d556854

Please sign in to comment.