Skip to content

test: [IV] Backend API Functional tests #940

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 17 commits into from
May 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 25 additions & 26 deletions code/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ def setup_default_mocking(httpserver: HTTPServer, app_config: AppConfig):
}
)

prime_search_to_trigger_creation_of_index(httpserver, app_config)

httpserver.expect_request(
"/indexes",
method="POST",
Expand Down Expand Up @@ -120,30 +118,6 @@ def setup_default_mocking(httpserver: HTTPServer, app_config: AppConfig):
}
)

httpserver.expect_request(
f"/indexes('{app_config.get('AZURE_SEARCH_INDEX')}')/docs/search.post.search",
method="POST",
).respond_with_json(
{
"value": [
{
"@search.score": 0.02916666865348816,
"id": "doc_1",
"content": "content",
"content_vector": [
-0.012909674,
0.00838491,
],
"metadata": '{"id": "doc_1", "source": "https://source", "title": "/documents/doc.pdf", "chunk": 95, "offset": 202738, "page_number": null}',
"title": "/documents/doc.pdf",
"source": "https://source",
"chunk": 95,
"offset": 202738,
}
]
}
)

httpserver.expect_request(
"/sts/v1.0/issueToken",
method="POST",
Expand Down Expand Up @@ -222,6 +196,7 @@ def setup_default_mocking(httpserver: HTTPServer, app_config: AppConfig):
httpserver.check()


@pytest.fixture(scope="function", autouse=True)
def prime_search_to_trigger_creation_of_index(
httpserver: HTTPServer, app_config: AppConfig
):
Expand All @@ -237,6 +212,30 @@ def prime_search_to_trigger_creation_of_index(
method="GET",
).respond_with_json({"value": [{"name": app_config.get("AZURE_SEARCH_INDEX")}]})

httpserver.expect_request(
f"/indexes('{app_config.get('AZURE_SEARCH_INDEX')}')/docs/search.post.search",
method="POST",
).respond_with_json(
{
"value": [
{
"@search.score": 0.02916666865348816,
"id": "doc_1",
"content": "content",
"content_vector": [
-0.012909674,
0.00838491,
],
"metadata": '{"id": "doc_1", "source": "https://source", "title": "/documents/doc.pdf", "chunk": 95, "offset": 202738, "page_number": null}',
"title": "/documents/doc.pdf",
"source": "https://source",
"chunk": 95,
"offset": 202738,
}
]
}
)


# This fixture can be overriden
@pytest.fixture(autouse=True)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import logging
import pytest
from pytest_httpserver import HTTPServer
from tests.functional.app_config import AppConfig
from tests.functional.tests.backend_api.common import get_free_port, start_app
from backend.batch.utilities.helpers.config.config_helper import ConfigHelper
from backend.batch.utilities.helpers.env_helper import EnvHelper

logger = logging.getLogger(__name__)


@pytest.fixture(scope="package")
def app_port() -> int:
logger.info("Getting free port")
return get_free_port()


@pytest.fixture(scope="package")
def app_url(app_port: int) -> str:
return f"http://localhost:{app_port}"


@pytest.fixture(scope="package")
def app_config(make_httpserver, ca):
logger.info("Creating APP CONFIG")
with ca.cert_pem.tempfile() as ca_temp_path:
app_config = AppConfig(
{
"AZURE_OPENAI_ENDPOINT": f"https://localhost:{make_httpserver.port}/",
"AZURE_SEARCH_SERVICE": f"https://localhost:{make_httpserver.port}/",
"AZURE_CONTENT_SAFETY_ENDPOINT": f"https://localhost:{make_httpserver.port}/",
"AZURE_SPEECH_REGION_ENDPOINT": f"https://localhost:{make_httpserver.port}/",
"AZURE_STORAGE_ACCOUNT_ENDPOINT": f"https://localhost:{make_httpserver.port}/",
"LOAD_CONFIG_FROM_BLOB_STORAGE": "False",
"AZURE_SEARCH_USE_INTEGRATED_VECTORIZATION": "True",
"SSL_CERT_FILE": ca_temp_path,
"CURL_CA_BUNDLE": ca_temp_path,
}
)
logger.info(f"Created app config: {app_config.get_all()}")
yield app_config


@pytest.fixture(scope="package", autouse=True)
def manage_app(app_port: int, app_config: AppConfig):
app_config.apply_to_environment()
EnvHelper.clear_instance()
ConfigHelper.clear_config()
start_app(app_port)
yield
app_config.remove_from_environment()
EnvHelper.clear_instance()
ConfigHelper.clear_config()


@pytest.fixture(scope="function", autouse=True)
def prime_search_to_trigger_creation_of_index(
httpserver: HTTPServer, app_config: AppConfig
):
httpserver.expect_request(
"/indexes",
method="GET",
).respond_with_json({"value": [{"name": app_config.get("AZURE_SEARCH_INDEX")}]})

httpserver.expect_request(
f"/indexes('{app_config.get('AZURE_SEARCH_INDEX')}')/docs/search.post.search",
method="POST",
).respond_with_json(
{
"value": [
{
"@search.score": 0.8008686,
"id": "aHR0cHM6Ly9zdHJ2bzRoNWZheWthd3NnLmJsb2IuY29yZS53aW5kb3dzLm5ldC9kb2N1bWVudHMvQmVuZWZpdF9PcHRpb25zLnBkZg2",
"content": "content",
"content_vector": [
-0.012909674,
0.00838491,
],
"metadata": None,
"title": "doc.pdf",
"source": "https://source",
"chunk": None,
"offset": None,
"chunk_id": "31e6a74d1340_aHR0cHM6Ly9zdHJ2bzRoNWZheWthd3NnLmJsb2IuY29yZS53aW5kb3dzLm5ldC9kb2N1bWVudHMvQmVuZWZpdF9PcHRpb25zLnBkZg2_pages_6",
}
]
}
)
Loading