Skip to content
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

test: [IV] Functional tests for IV backend function #938

Merged
merged 14 commits into from
May 20, 2024
1 change: 0 additions & 1 deletion code/backend/batch/batch_start_processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
import json
import azure.functions as func

from utilities.helpers.embedders.integrated_vectorization_embedder import (
IntegratedVectorizationEmbedder,
)
Expand Down
47 changes: 47 additions & 0 deletions code/tests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,53 @@ def setup_default_mocking(httpserver: HTTPServer, app_config: AppConfig):
}
)

httpserver.expect_request(
f"/datasources('{app_config.get('AZURE_SEARCH_DATASOURCE_NAME')}')",
method="PUT",
).respond_with_json({}, status=201)

httpserver.expect_request(
f"/indexes('{app_config.get('AZURE_SEARCH_INDEX')}')",
method="PUT",
).respond_with_json({}, status=201)

httpserver.expect_request(
f"/skillsets('{app_config.get('AZURE_SEARCH_INDEX')}-skillset')",
method="PUT",
).respond_with_json(
{
"name": f"{app_config.get('AZURE_SEARCH_INDEX')}-skillset",
"description": "Extract entities, detect language and extract key-phrases",
"skills": [
{
"@odata.type": "#Microsoft.Skills.Text.SplitSkill",
"name": "#3",
"description": None,
"context": None,
"inputs": [
{"name": "text", "source": "/document/content"},
{"name": "languageCode", "source": "/document/languageCode"},
],
"outputs": [{"name": "textItems", "targetName": "pages"}],
"defaultLanguageCode": None,
"textSplitMode": "pages",
"maximumPageLength": 4000,
},
],
},
status=201,
)

httpserver.expect_request(
f"/indexers('{app_config.get('AZURE_SEARCH_INDEXER_NAME')}')",
method="PUT",
).respond_with_json({}, status=201)

httpserver.expect_request(
f"/indexers('{app_config.get('AZURE_SEARCH_INDEXER_NAME')}')/search.run",
method="POST",
).respond_with_json({}, status=202)

yield

httpserver.check()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import logging
import os
import sys
import pytest
from tests.functional.app_config import AppConfig
from backend.batch.utilities.helpers.config.config_helper import ConfigHelper
from backend.batch.utilities.helpers.env_helper import EnvHelper

sys.path.append(
os.path.join(os.path.dirname(sys.path[0]), "..", "..", "..", "backend", "batch")
)
# The below imports are needed due to the sys.path.append above as the backend function is not aware of the folders outside of the function
from utilities.helpers.config.config_helper import ConfigHelper # noqa: E402
adamdougal marked this conversation as resolved.
Show resolved Hide resolved
from utilities.helpers.env_helper import EnvHelper # noqa: E402

logger = logging.getLogger(__name__)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import hashlib
import json
import os
import sys
from unittest.mock import ANY

from azure.functions import QueueMessage
Expand All @@ -15,12 +13,7 @@
COMPUTER_VISION_VECTORIZE_IMAGE_PATH,
COMPUTER_VISION_VECTORIZE_IMAGE_REQUEST_METHOD,
)

sys.path.append(
os.path.join(os.path.dirname(sys.path[0]), "..", "..", "backend", "batch")
)

from backend.batch.batch_push_results import batch_push_results # noqa: E402
from backend.batch.batch_push_results import batch_push_results

pytestmark = pytest.mark.functional

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import logging
import os
import sys
import pytest

from tests.functional.app_config import AppConfig

sys.path.append(
os.path.join(os.path.dirname(sys.path[0]), "..", "..", "..", "backend", "batch")
)
# The below imports are needed due to the sys.path.append above as the backend function is not aware of the folders outside of the function
from utilities.helpers.config.config_helper import ConfigHelper # noqa: E402
from utilities.helpers.env_helper import EnvHelper # noqa: E402

logger = logging.getLogger(__name__)


@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}/",
"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_config: AppConfig):
app_config.apply_to_environment()
EnvHelper.clear_instance()
ConfigHelper.clear_config()
yield
app_config.remove_from_environment()
EnvHelper.clear_instance()
ConfigHelper.clear_config()
Loading