diff --git a/MinuteMate/back/tests/__init__.py b/MinuteMate/back/tests/__init__.py new file mode 100644 index 00000000..94ecca8f --- /dev/null +++ b/MinuteMate/back/tests/__init__.py @@ -0,0 +1,4 @@ +# pip install pytest pytest-asyncio pytest-cov + +# Running the tests +# pytest --cov=app tests/ -v \ No newline at end of file diff --git a/MinuteMate/back/tests/conftest.py b/MinuteMate/back/tests/conftest.py new file mode 100644 index 00000000..12bff9be --- /dev/null +++ b/MinuteMate/back/tests/conftest.py @@ -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 \ No newline at end of file diff --git a/MinuteMate/back/tests/test_api.py b/MinuteMate/back/tests/test_api.py new file mode 100644 index 00000000..92d1fca4 --- /dev/null +++ b/MinuteMate/back/tests/test_api.py @@ -0,0 +1,25 @@ +import pytest +from fastapi.testclient import TestClient +from app.main import app # Adjust import path + +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 + assert "generated_response" in response.json() + +def test_process_prompt_invalid_request(test_client): + response = test_client.post( + "/process-prompt", + json={"user_prompt_text": ""} + ) + assert response.status_code == 422 + +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 \ No newline at end of file diff --git a/MinuteMate/back/tests/test_config.py b/MinuteMate/back/tests/test_config.py new file mode 100644 index 00000000..5c7b280c --- /dev/null +++ b/MinuteMate/back/tests/test_config.py @@ -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' + assert processor.WEAVIATE_URL == 'test-weaviate-url' + assert processor.WEAVIATE_API_KEY == 'test-weaviate-key' + +def test_prompt_processor_missing_env_vars(): + with patch.dict(os.environ, {}, clear=True): + with pytest.raises(ValueError): + PromptProcessor() \ No newline at end of file diff --git a/MinuteMate/back/tests/test_dependencies.py b/MinuteMate/back/tests/test_dependencies.py new file mode 100644 index 00000000..bfc8aeef --- /dev/null +++ b/MinuteMate/back/tests/test_dependencies.py @@ -0,0 +1,34 @@ +import pytest +from app.main import PromptProcessor, PromptRequest # Adjust import path + +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) + assert len(keywords) <= 3 + +def test_search_weaviate(mock_weaviate_client): + processor = PromptProcessor() + + # Mock the collection query response + mock_result = Mock() + 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) + assert isinstance(keywords, list) + +@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 + assert "generated_response" in response.json() + assert "context_segments" in response.json() + assert "keywords" in response.json() \ No newline at end of file