ai-video-generator / tests /test_main.py
officialsstein's picture
Upload 5 files
01787e4 verified
import pytest
from httpx import AsyncClient
import os
import asyncio
import sys
from pathlib import Path
ROOT_DIR = Path(__file__).resolve().parents[1]
APP_DIR = ROOT_DIR / "app"
if str(APP_DIR) not in sys.path:
sys.path.insert(0, str(APP_DIR))
from main import app
@pytest.mark.asyncio
async def test_generate_video():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.post("/generate", json={"prompt": "a sunset over the mountains"})
assert response.status_code == 200
assert "video_url" in response.json()
video_path = response.json()["video_url"].replace("/videos/", "generated_videos/")
assert os.path.exists(video_path)
@pytest.mark.asyncio
async def test_serve_video():
async with AsyncClient(app=app, base_url="http://test") as ac:
gen_response = await ac.post("/generate", json={"prompt": "a forest stream"})
assert gen_response.status_code == 200
video_url = gen_response.json()["video_url"]
get_response = await ac.get(video_url)
assert get_response.status_code == 200
assert get_response.headers["content-type"] == "video/mp4"
@pytest.mark.asyncio
async def test_serve_missing_video():
async with AsyncClient(app=app, base_url="http://test") as ac:
response = await ac.get("/videos/this_file_does_not_exist.mp4")
assert response.status_code == 404
assert response.json()["detail"] == "Video not found"