diff --git a/code/tests/functional/tests/backend_api/default/test_conversation.py b/code/tests/functional/tests/backend_api/default/test_conversation.py index 70d567e14..b86feda1c 100644 --- a/code/tests/functional/tests/backend_api/default/test_conversation.py +++ b/code/tests/functional/tests/backend_api/default/test_conversation.py @@ -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 ( @@ -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) diff --git a/code/tests/functional/tests/backend_api/with_byod/test_conversation_flow.py b/code/tests/functional/tests/backend_api/with_byod/test_conversation_flow.py index b9ea5e7f0..ef3b29c2c 100644 --- a/code/tests/functional/tests/backend_api/with_byod/test_conversation_flow.py +++ b/code/tests/functional/tests/backend_api/with_byod/test_conversation_flow.py @@ -1,6 +1,7 @@ import json import pytest from pytest_httpserver import HTTPServer +from unittest.mock import patch import requests from string import Template @@ -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) diff --git a/code/tests/functional/tests/backend_api/without_data/test_azure_byod_without_data.py b/code/tests/functional/tests/backend_api/without_data/test_azure_byod_without_data.py index f453e8ec0..c903b8eb3 100644 --- a/code/tests/functional/tests/backend_api/without_data/test_azure_byod_without_data.py +++ b/code/tests/functional/tests/backend_api/without_data/test_azure_byod_without_data.py @@ -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, @@ -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) @@ -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) diff --git a/code/tests/utilities/helpers/test_config_helper.py b/code/tests/utilities/helpers/test_config_helper.py index 0c2c990dd..f4de97014 100644 --- a/code/tests/utilities/helpers/test_config_helper.py +++ b/code/tests/utilities/helpers/test_config_helper.py @@ -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",