Spaces:
Running
Running
| import pytest | |
| from httpx import AsyncClient | |
| from unittest.mock import patch, MagicMock | |
| async def test_e2e_smart_lifecycle(async_client: AsyncClient, auth_headers): | |
| # Mock LLM calls to prevent spending credits/failing on missing keys during tests | |
| with patch("endpoints.projects.get_llm") as mock_compile_llm, patch( | |
| "agents.helpers.wizard_node" | |
| ) as mock_wizard_node, patch( | |
| "rag_pipeline.vector_store.get_vector_store" | |
| ) as mock_pinecone: | |
| mock_pinecone.return_value = MagicMock() | |
| mock_pinecone.return_value.as_retriever.return_value.invoke.return_value = [ | |
| MagicMock(page_content="Zmockowany kontekst RAG z Pinecone") | |
| ] | |
| # Mocking wizard_node return for section generation | |
| valid_mock_content = ( | |
| "Przykładowa testowa treść wniosku o dofinansowanie. " * 100 | |
| + "\n\n| Tabela | Koszt |\n|---|---|\n| Zadanie 1 | 1000 PLN |\n\n" | |
| + "Dodatkowy tekst wypełniający, aby osiągnąć odpowiednią długość. " * 100 | |
| ) | |
| if len(valid_mock_content) < 5000: | |
| valid_mock_content += "A" * (5000 - len(valid_mock_content)) | |
| mock_wizard_node.return_value = { | |
| "messages": [MagicMock(content=valid_mock_content)] | |
| } | |
| mock_response = MagicMock() | |
| mock_response.content = valid_mock_content | |
| mock_compile_llm.return_value = MagicMock() | |
| mock_compile_llm.return_value.invoke.return_value = mock_response | |
| mock_compile_llm.return_value.return_value = mock_response | |
| # 1. Create a SMART project | |
| payload = { | |
| "title": "Test SMART E2E", | |
| "program_name": "FENG.01.01-IP.02-001/23", | |
| "program_type": "smart", | |
| "description": "Test E2E", | |
| } | |
| response = await async_client.post( | |
| "/api/projects", json=payload, headers=auth_headers | |
| ) | |
| assert response.status_code == 200 | |
| project_id = response.json()["id"] | |
| # 2. Get generated structure (sections) | |
| response = await async_client.get( | |
| f"/api/projects/{project_id}/sections", headers=auth_headers | |
| ) | |
| assert response.status_code == 200 | |
| sections = response.json() | |
| assert len(sections) > 0, "Brak sekcji startowych dla SMART" | |
| # 3. Generate a specific section (e.g., project_description) | |
| payload_gen = { | |
| "section_type": "project_description", | |
| "prompt_context": "Opis innowacji test", | |
| } | |
| response = await async_client.post( | |
| f"/api/projects/{project_id}/generate-section", | |
| json=payload_gen, | |
| headers=auth_headers, | |
| ) | |
| assert response.status_code == 200 | |
| assert "Przykładowa testowa treść" in response.json()["content"] | |
| # 4. Generate final document | |
| payload_compile = {"approved_only": False} | |
| response = await async_client.post( | |
| f"/api/projects/{project_id}/compile-final", | |
| json=payload_compile, | |
| headers=auth_headers, | |
| ) | |
| assert response.status_code == 200 | |
| assert "final_markdown" in response.json() | |
| assert "Przykładowa testowa treść" in response.json()["final_markdown"] | |