-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# pip install pytest pytest-asyncio pytest-cov | ||
|
||
# Running the tests | ||
# pytest --cov=app tests/ -v |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
from fastapi.testclient import TestClient | ||
from unittest.mock import Mock, patch | ||
from typing import Generator | ||
|
||
from app.main import app # Adjust import path as needed | ||
|
||
@pytest.fixture | ||
def test_client() -> Generator: | ||
with TestClient(app) as client: | ||
yield client | ||
|
||
@pytest.fixture | ||
def mock_weaviate_client(): | ||
with patch('weaviate.connect_to_weaviate_cloud') as mock: | ||
mock_client = Mock() | ||
mock.return_value = mock_client | ||
yield mock_client | ||
|
||
@pytest.fixture | ||
def mock_openai_client(): | ||
with patch('openai.OpenAI') as mock: | ||
mock_client = Mock() | ||
mock.return_value = mock_client | ||
yield mock_client |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import pytest | ||
Check failure on line 1 in MinuteMate/back/tests/test_api.py GitHub Actions / ruffRuff (F401)
|
||
from fastapi.testclient import TestClient | ||
Check failure on line 2 in MinuteMate/back/tests/test_api.py GitHub Actions / ruffRuff (F401)
|
||
from app.main import app # Adjust import path | ||
Check failure on line 3 in MinuteMate/back/tests/test_api.py GitHub Actions / ruffRuff (F401)
|
||
|
||
def test_process_prompt_valid_request(test_client): | ||
response = test_client.post( | ||
"/process-prompt", | ||
json={"user_prompt_text": "Test prompt"} | ||
) | ||
assert response.status_code == 200 | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert "generated_response" in response.json() | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
def test_process_prompt_invalid_request(test_client): | ||
response = test_client.post( | ||
"/process-prompt", | ||
json={"user_prompt_text": ""} | ||
) | ||
assert response.status_code == 422 | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
def test_process_prompt_long_text(test_client): | ||
response = test_client.post( | ||
"/process-prompt", | ||
json={"user_prompt_text": "a" * 1001} | ||
) | ||
assert response.status_code == 422 | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import pytest | ||
import os | ||
from unittest.mock import patch | ||
from app.main import WeaviateConfig, PromptProcessor # Adjust import path | ||
|
||
def test_weaviate_config_initialization(): | ||
test_url = "https://test-url" | ||
test_api_key = "test-key" | ||
|
||
with patch('weaviate.connect_to_weaviate_cloud') as mock_connect: | ||
WeaviateConfig.get_weaviate_client(test_url, test_api_key) | ||
mock_connect.assert_called_once() | ||
|
||
def test_prompt_processor_env_vars(): | ||
test_env_vars = { | ||
'OPENAI_API_KEY': 'test-openai-key', | ||
'WEAVIATE_URL': 'test-weaviate-url', | ||
'WEAVIATE_API_KEY': 'test-weaviate-key' | ||
} | ||
|
||
with patch.dict(os.environ, test_env_vars): | ||
processor = PromptProcessor() | ||
assert processor.OPENAI_API_KEY == 'test-openai-key' | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert processor.WEAVIATE_URL == 'test-weaviate-url' | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert processor.WEAVIATE_API_KEY == 'test-weaviate-key' | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
def test_prompt_processor_missing_env_vars(): | ||
with patch.dict(os.environ, {}, clear=True): | ||
with pytest.raises(ValueError): | ||
PromptProcessor() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import pytest | ||
from app.main import PromptProcessor, PromptRequest # Adjust import path | ||
Check failure on line 2 in MinuteMate/back/tests/test_dependencies.py GitHub Actions / ruffRuff (F401)
|
||
|
||
def test_extract_keywords(mock_weaviate_client): | ||
processor = PromptProcessor() | ||
text = "This is a test meeting about project planning and team coordination" | ||
keywords = processor.extract_keywords(text) | ||
assert isinstance(keywords, list) | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert len(keywords) <= 3 | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
def test_search_weaviate(mock_weaviate_client): | ||
processor = PromptProcessor() | ||
|
||
# Mock the collection query response | ||
mock_result = Mock() | ||
Check failure on line 15 in MinuteMate/back/tests/test_dependencies.py GitHub Actions / ruffRuff (F821)
|
||
mock_result.objects = [] | ||
mock_weaviate_client.collections.get().query.bm25.return_value = mock_result | ||
|
||
context_segments, keywords = processor.search_weaviate("test query") | ||
assert isinstance(context_segments, list) | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert isinstance(keywords, list) | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
|
||
@pytest.mark.asyncio | ||
async def test_process_prompt_endpoint(test_client): | ||
test_prompt = "Test prompt" | ||
response = test_client.post( | ||
"/process-prompt", | ||
json={"user_prompt_text": test_prompt} | ||
) | ||
|
||
assert response.status_code == 200 | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert "generated_response" in response.json() | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert "context_segments" in response.json() | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|
||
assert "keywords" in response.json() | ||
Check notice Code scanning / Bandit Use of assert detected. The enclosed code will be removed when compiling to optimised byte code. Note test
Use of assert detected. The enclosed code will be removed when compiling to optimised byte code.
|