"""Tests for web API endpoints.""" from fastapi.testclient import TestClient from src.web.app import app client = TestClient(app) class TestHealthEndpoints: def test_root_returns_html(self): response = client.get("/") assert response.status_code == 200 assert "text/html" in response.headers["content-type"] def test_get_config(self): response = client.get("/api/config") assert response.status_code == 200 def test_get_stats(self): response = client.get("/api/stats") assert response.status_code == 200 data = response.json() assert "total_posts" in data def test_get_collector_status(self): response = client.get("/api/collector/status") assert response.status_code == 200 data = response.json() assert "running" in data def test_get_media_files(self): response = client.get("/api/media?limit=10") assert response.status_code == 200 data = response.json() assert "files" in data assert "total" in data def test_get_subreddits(self): response = client.get("/api/subreddits") assert response.status_code == 200 def test_get_users(self): response = client.get("/api/users") assert response.status_code == 200 def test_get_blacklist(self): response = client.get("/api/blacklist") assert response.status_code == 200 def test_get_settings(self): response = client.get("/api/settings") assert response.status_code == 200 class TestMediaEndpoints: def test_file_not_found(self): response = client.get("/api/media/file/nonexistent.jpg") assert response.status_code == 404 def test_thumb_not_found(self): response = client.get("/api/media/thumb/nonexistent.mp4") assert response.status_code == 404 def test_media_info_not_found(self): response = client.get("/api/media/nonexistent/info") assert response.status_code == 404 def test_delete_media_not_found(self): response = client.delete("/api/media/nonexistent") assert response.status_code == 404 class TestValidation: def test_cleanup_invalid_media_type(self): response = client.get("/api/media/cleanup-preview?media_type=invalid") assert response.status_code == 400 def test_collect_invalid_target_type(self): response = client.post( "/api/collect/individual", json={"target_type": "invalid", "target_name": "test"}, ) assert response.status_code == 400