presenton/servers/fastapi/tests/test_presentation_generation_api.py
sudipnext c7860127f2 feat: add support for optional embedded Ollama and enhance database migration handling
- Updated docker-compose.yml to allow disabling embedded Ollama via environment variable.
- Refactored Dockerfile and Dockerfile.dev for improved dependency management and installation process.
- Enhanced FastAPI migration scripts to handle orphaned Alembic revisions and added new database migration logic.
- Improved error handling in background tasks and Codex authentication endpoints.
- Added support for font file uploads with better validation and extraction of font names.
- Introduced new image search functionality with support for Pexels and Pixabay APIs.
2026-04-15 15:39:35 +05:45

117 lines
3.9 KiB
Python

import asyncio
import uuid
from unittest.mock import AsyncMock, patch
import pytest
from fastapi import HTTPException
from pydantic import ValidationError
from api.v1.ppt.endpoints.presentation import generate_presentation_sync
from models.generate_presentation_request import GeneratePresentationRequest
from models.presentation_and_path import PresentationPathAndEditPath
class FakeAsyncSession:
async def get(self, *_args, **_kwargs):
return None
def add(self, *_args, **_kwargs):
return None
def add_all(self, *_args, **_kwargs):
return None
async def commit(self):
return None
class TestPresentationGenerationAPI:
def test_generate_presentation_export_as_pdf(self):
request = GeneratePresentationRequest(
content="Create a presentation about artificial intelligence and machine learning",
n_slides=5,
language="English",
export_as="pdf",
template="general",
)
response_payload = PresentationPathAndEditPath(
presentation_id=uuid.uuid4(),
path="/tmp/exports/test.pdf",
edit_path="/presentation?id=test",
)
with patch(
"api.v1.ppt.endpoints.presentation.generate_presentation_handler",
new=AsyncMock(return_value=response_payload),
) as mock_handler:
response = asyncio.run(
generate_presentation_sync(request, sql_session=FakeAsyncSession())
)
assert response == response_payload
mock_handler.assert_awaited_once()
def test_generate_presentation_export_as_pptx(self):
request = GeneratePresentationRequest(
content="Create a presentation about artificial intelligence and machine learning",
n_slides=5,
language="English",
export_as="pptx",
template="general",
)
response_payload = PresentationPathAndEditPath(
presentation_id=uuid.uuid4(),
path="/tmp/exports/test.pptx",
edit_path="/presentation?id=test",
)
with patch(
"api.v1.ppt.endpoints.presentation.generate_presentation_handler",
new=AsyncMock(return_value=response_payload),
) as mock_handler:
response = asyncio.run(
generate_presentation_sync(request, sql_session=FakeAsyncSession())
)
assert response == response_payload
mock_handler.assert_awaited_once()
def test_generate_presentation_with_no_content(self):
with pytest.raises(ValidationError):
GeneratePresentationRequest.model_validate(
{
"n_slides": 5,
"language": "English",
"export_as": "pdf",
"template": "general",
}
)
def test_generate_presentation_with_n_slides_less_than_one(self):
request = GeneratePresentationRequest(
content="Create a presentation about artificial intelligence and machine learning",
n_slides=0,
language="English",
export_as="pdf",
template="general",
)
with pytest.raises(HTTPException) as exc:
asyncio.run(
generate_presentation_sync(request, sql_session=FakeAsyncSession())
)
assert exc.value.status_code == 400
assert exc.value.detail == "Number of slides must be greater than 0"
def test_generate_presentation_with_invalid_export_type(self):
with pytest.raises(ValidationError):
GeneratePresentationRequest.model_validate(
{
"content": "Create a presentation about artificial intelligence and machine learning",
"n_slides": 5,
"language": "English",
"export_as": "invalid_type",
"template": "general",
}
)