Merge pull request #1 from presenton/initial-tests
add few initial tests
This commit is contained in:
commit
33ce4747c3
9 changed files with 146 additions and 46 deletions
Binary file not shown.
BIN
servers/fastapi/tests/assets/impact_of_llms.pdf
Normal file
BIN
servers/fastapi/tests/assets/impact_of_llms.pdf
Normal file
Binary file not shown.
Binary file not shown.
34
servers/fastapi/tests/test_document_decompose.py
Normal file
34
servers/fastapi/tests/test_document_decompose.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
import os
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from api.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def test_upload_and_decompose_document():
|
||||
# Get the absolute path to the test asset
|
||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
file_path = os.path.join(current_dir, "assets", "impact_of_llms.pdf")
|
||||
|
||||
# Step 1: Upload the document
|
||||
with open(file_path, "rb") as f:
|
||||
upload_response = client.post(
|
||||
"/ppt/files/upload",
|
||||
files={"documents": ("impact_of_llms.pdf", f, "application/pdf")}
|
||||
)
|
||||
assert upload_response.status_code == 200
|
||||
upload_json = upload_response.json()
|
||||
assert "documents" in upload_json
|
||||
assert len(upload_json["documents"]) > 0
|
||||
|
||||
# Step 2: Decompose the uploaded document
|
||||
decompose_response = client.post(
|
||||
"/ppt/files/decompose",
|
||||
json={"documents": upload_json["documents"]}
|
||||
)
|
||||
assert decompose_response.status_code == 200
|
||||
decompose_json = decompose_response.json()
|
||||
assert "documents" in decompose_json
|
||||
# Verify the decomposition created a text file for the uploaded document
|
||||
assert upload_json["documents"][0] in decompose_json["documents"]
|
||||
assert decompose_json["documents"][upload_json["documents"][0]].endswith(".txt")
|
||||
24
servers/fastapi/tests/test_document_upload.py
Normal file
24
servers/fastapi/tests/test_document_upload.py
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
from fastapi.testclient import TestClient
|
||||
from api.main import app
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
file = "tests/assets/impact_of_llms.pdf"
|
||||
|
||||
def test_upload_files():
|
||||
with open(file, "rb") as f:
|
||||
response = client.post(
|
||||
"/ppt/files/upload",
|
||||
files={"documents": ("impact_of_llms.pdf", f, "application/pdf")},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
assert "documents" in response_json
|
||||
assert "images" in response_json
|
||||
|
||||
def test_upload_files_no_files():
|
||||
response = client.post("/ppt/files/upload")
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
assert response_json["documents"] == []
|
||||
assert response_json["images"] == []
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
from image_processor.images_finder import generate_image
|
||||
from ppt_generator.models.query_and_prompt_models import (
|
||||
ImageAspectRatio,
|
||||
ImagePromptWithThemeAndAspectRatio,
|
||||
)
|
||||
|
||||
|
||||
async def test_image_generation():
|
||||
await generate_image(
|
||||
ImagePromptWithThemeAndAspectRatio(
|
||||
image_prompt="halloween night at a haunted museum",
|
||||
theme_prompt="halloween",
|
||||
aspect_ratio=ImageAspectRatio.r_1_1,
|
||||
),
|
||||
output_path="/tmp/presenton/generated_image.jpg",
|
||||
)
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
from research_report.generator import get_report
|
||||
|
||||
|
||||
async def test_research_report_generator():
|
||||
query = "global warming"
|
||||
language = "English"
|
||||
report = await get_report(query, language)
|
||||
print(report)
|
||||
88
servers/fastapi/tests/test_stream_presentation.py
Normal file
88
servers/fastapi/tests/test_stream_presentation.py
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
from unittest.mock import patch, MagicMock
|
||||
from fastapi.testclient import TestClient
|
||||
import json
|
||||
|
||||
from api.main import app
|
||||
from api.models import SessionModel
|
||||
|
||||
client = TestClient(app)
|
||||
|
||||
def mock_stream_response():
|
||||
return [
|
||||
{"type": "start", "data": "Starting presentation generation"},
|
||||
{"type": "slide_start", "data": "Generating slide 1"},
|
||||
{"type": "slide_end", "data": "Completed slide 1"},
|
||||
{"type": "slide_start", "data": "Generating slide 2"},
|
||||
{"type": "slide_end", "data": "Completed slide 2"},
|
||||
{"type": "end", "data": "Presentation generation complete"}
|
||||
]
|
||||
|
||||
@patch('api.routers.presentation.handlers.generate_stream.PresentationGenerateStreamHandler.get')
|
||||
def test_presentation_flow(mock_stream):
|
||||
# Setup mock for streaming response
|
||||
mock_stream.return_value = mock_stream_response()
|
||||
|
||||
# Step 1: Upload document
|
||||
test_file_path = "tests/assets/impact_of_llms.pdf"
|
||||
with open(test_file_path, "rb") as f:
|
||||
upload_response = client.post(
|
||||
"/ppt/files/upload",
|
||||
files={"documents": ("impact_of_llms.pdf", f, "application/pdf")}
|
||||
)
|
||||
assert upload_response.status_code == 200
|
||||
upload_json = upload_response.json()
|
||||
assert "documents" in upload_json
|
||||
assert len(upload_json["documents"]) > 0
|
||||
|
||||
# Step 2: Decompose uploaded document
|
||||
decompose_response = client.post(
|
||||
"/ppt/files/decompose",
|
||||
json={"documents": upload_json["documents"]}
|
||||
)
|
||||
assert decompose_response.status_code == 200
|
||||
decompose_json = decompose_response.json()
|
||||
assert "documents" in decompose_json
|
||||
assert upload_json["documents"][0] in decompose_json["documents"]
|
||||
|
||||
# Step 3: Create presentation
|
||||
create_response = client.post(
|
||||
"/ppt/create",
|
||||
json={
|
||||
"prompt": "Create a presentation about LLMs",
|
||||
"n_slides": 2,
|
||||
"language": "en",
|
||||
"documents": upload_json["documents"]
|
||||
}
|
||||
)
|
||||
assert create_response.status_code == 200
|
||||
presentation = create_response.json()
|
||||
presentation_id = presentation["id"]
|
||||
|
||||
# Step 4: Generate presentation data and get session
|
||||
gen_data_response = client.post(
|
||||
"/ppt/generate/data",
|
||||
json={
|
||||
"presentation_id": presentation_id,
|
||||
"theme": None,
|
||||
"images": None,
|
||||
"watermark": True,
|
||||
"titles": ["Introduction to LLMs", "Impact of LLMs"]
|
||||
}
|
||||
)
|
||||
assert gen_data_response.status_code == 200
|
||||
session_data = gen_data_response.json()
|
||||
assert "session" in session_data
|
||||
|
||||
# Step 5: Stream presentation generation
|
||||
stream_response = client.get(f"/ppt/generate/stream?presentation_id={presentation_id}&session={session_data['session']}")
|
||||
assert stream_response.status_code == 200
|
||||
|
||||
# Verify stream events
|
||||
events = list(mock_stream_response())
|
||||
assert len(events) > 0
|
||||
assert events[0]["type"] == "start"
|
||||
assert events[-1]["type"] == "end"
|
||||
assert any(event["type"] == "slide_start" for event in events)
|
||||
assert any(event["type"] == "slide_end" for event in events)
|
||||
|
||||
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
import asyncio
|
||||
from dotenv import load_dotenv
|
||||
|
||||
load_dotenv()
|
||||
|
||||
from document_processor.loader import DocumentsLoader
|
||||
from ppt_config_generator.document_summary_generator import generate_document_summary
|
||||
from api.services.instances import temp_file_service
|
||||
|
||||
|
||||
async def test_generate_document_summary():
|
||||
documents_loader = DocumentsLoader(
|
||||
[
|
||||
"tests/assets/the_sun.pdf",
|
||||
]
|
||||
)
|
||||
temp_dir = temp_file_service.create_temp_dir()
|
||||
await documents_loader.load_documents(temp_dir)
|
||||
|
||||
summary = await generate_document_summary(documents_loader.documents)
|
||||
print(summary)
|
||||
assert summary is not None
|
||||
Loading…
Add table
Reference in a new issue