Skip to content

Commit

Permalink
Merge branch 'main' of https://git.muenchen.de/kicc/mucgpt
Browse files Browse the repository at this point in the history
  • Loading branch information
Meteord committed Jun 26, 2024
2 parents f3c2ede + 2de40b0 commit cb720fd
Show file tree
Hide file tree
Showing 20 changed files with 529 additions and 448 deletions.
Empty file added app/backend/__init__.py
Empty file.
2 changes: 1 addition & 1 deletion app/backend/init_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async def initApp() -> AppConfig:
password=DB_PASSWORD
)
# read enviornment config
config_helper = ConfigHelper(base_path=os.getcwd()+"/ressources/", env=CONFIG_NAME, base_config_name="base")
config_helper = ConfigHelper(base_path=os.path.dirname(os.path.realpath(__file__))+"/ressources/", env=CONFIG_NAME, base_config_name="base")
cfg = config_helper.loadData()

model_info = AzureChatGPTConfig(
Expand Down
21 changes: 21 additions & 0 deletions app/backend/ressources/test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"frontend": {
"labels": {
"env_name": "MUCGPT-Test"
},
"alternative_logo": false
},
"backend": {
"enable_auth": false,
"enable_database": false,
"chat":{
"log_tokens": false
},
"brainstorm": {
"log_tokens": false
},
"sum": {
"log_tokens": false
}
}
}
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ line-length = 300
[tool.pytest.ini_options]
addopts = "-ra --cov"
pythonpath = ["app/backend"]
testpaths = [
"tests"]
markers = [
"integration: mark a test as a integration test",
"unit: mark test as a unit test"
]

[tool.coverage.paths]
source = ["scripts", "app"]
Expand Down
1 change: 1 addition & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ black
pytest
pytest-asyncio
pytest-snapshot
pytest-mock
coverage
pytest-cov
pre-commit
Expand Down
Empty file added tests/__init__.py
Empty file.
109 changes: 0 additions & 109 deletions tests/conftest.py

This file was deleted.

Empty file added tests/integration/__init__.py
Empty file.
72 changes: 72 additions & 0 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
from collections import namedtuple

import openai
import pytest
import pytest_asyncio

import app

MockToken = namedtuple("MockToken", ["token", "expires_on"])


class MockAzureCredential:
async def get_token(self, uri):
return MockToken("mock_token", 9999999999)



@pytest.fixture
def mock_openai_chatcompletion(monkeypatch):
class AsyncChatCompletionIterator:
def __init__(self, answer):
self.num = 1
self.answer = answer

def __aiter__(self):
return self

async def __anext__(self):
if self.num == 1:
self.num = 0
return openai.util.convert_to_openai_object({"choices": [{"delta": {"content": self.answer}}]})
else:
raise StopAsyncIteration

async def mock_acreate(*args, **kwargs):
messages = kwargs["messages"]
if messages[-1]["content"] == "Generate search query for: What is the capital of France?":
answer = "capital of France"
else:
answer = "The capital of France is Paris."
if "stream" in kwargs and kwargs["stream"] is True:
return AsyncChatCompletionIterator(answer)
else:
return openai.util.convert_to_openai_object({"choices": [{"message": {"content": answer}}]})

monkeypatch.setattr(openai.ChatCompletion, "acreate", mock_acreate)



@pytest_asyncio.fixture
async def client(monkeypatch, mock_openai_chatcompletion):
monkeypatch.setenv("AZURE_OPENAI_SERVICE", "test-openai-service")
monkeypatch.setenv("AZURE_OPENAI_CHATGPT_DEPLOYMENT", "test-chatgpt")
monkeypatch.setenv("AZURE_OPENAI_CHATGPT_MODEL", "gpt-35-turbo")
monkeypatch.setenv("AZURE_OPENAI_EMB_DEPLOYMENT", "test-ada")
monkeypatch.setenv("SSO_ISSUER", "testissuer.de")
monkeypatch.setenv("CONFIG_NAME", "test")
monkeypatch.setenv("DB_HOST", "not used")
monkeypatch.setenv("DB_NAME", "not used")
monkeypatch.setenv("DB_PASSWORD", "not used")
monkeypatch.setenv("DB_USER", "not used")


#with mock.patch("app.DefaultAzureCredential") as mock_default_azure_credential:
#mock_default_azure_credential.return_value = MockAzureCredential()
quart_app = app.create_app()

async with quart_app.test_app() as test_app:
quart_app.config.update({"TESTING": True})

yield test_app.test_client()

Loading

0 comments on commit cb720fd

Please sign in to comment.