-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
229 additions
and
211 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,47 @@ | ||
import os | ||
from typing import Mapping | ||
|
||
import httpx | ||
import pytest | ||
import pytest_asyncio | ||
from httpx import ASGITransport | ||
from openai import AsyncAzureOpenAI | ||
|
||
from tests.utils.server import server_generator | ||
|
||
DEFAULT_API_VERSION = "2023-03-15-preview" | ||
TEST_SERVER_URL = os.getenv("TEST_SERVER_URL", "http://0.0.0.0:5001") | ||
@pytest.fixture(autouse=True) | ||
def configure_unit_tests(monkeypatch, request): | ||
""" | ||
Set up fake environment variables for unit tests. | ||
""" | ||
if "tests/unit_tests" in request.node.nodeid: | ||
monkeypatch.setenv("AWS_DEFAULT_REGION", "test-region") | ||
|
||
|
||
@pytest.fixture(scope="module") | ||
def server(): | ||
yield from server_generator( | ||
"aidial_adapter_bedrock.app:app", TEST_SERVER_URL | ||
) | ||
@pytest_asyncio.fixture | ||
async def test_http_client(): | ||
from aidial_adapter_bedrock.app import app | ||
|
||
async with httpx.AsyncClient( | ||
transport=ASGITransport(app), # type: ignore | ||
base_url="http://test-app.com", | ||
) as client: | ||
yield client | ||
|
||
|
||
@pytest.fixture | ||
def get_openai_client(test_http_client: httpx.AsyncClient): | ||
def _get_client( | ||
deployment_id: str | None = None, | ||
extra_headers: Mapping[str, str] | None = None, | ||
) -> AsyncAzureOpenAI: | ||
return AsyncAzureOpenAI( | ||
azure_endpoint=str(test_http_client.base_url), | ||
azure_deployment=deployment_id, | ||
api_version="", | ||
api_key="dummy_key", | ||
max_retries=2, | ||
timeout=30, | ||
http_client=test_http_client, | ||
default_headers=extra_headers, | ||
) | ||
|
||
yield _get_client |
Oops, something went wrong.