"""Tests for sitemap API endpoints — /api/sitemap/sitemap.xml, /api/sitemap/robots.txt, /api/sitemap/regenerate.""" import pytest from httpx import AsyncClient from starlette.testclient import TestClient from app.main import app class TestSitemapEndpoints: """Tests for sitemap API routes.""" def _client(self): return TestClient(app) def test_sitemap_xml_status(self): client = self._client() resp = client.get("/api/sitemap/sitemap.xml") assert resp.status_code == 200 def test_sitemap_xml_content_type(self): client = self._client() resp = client.get("/api/sitemap/sitemap.xml") assert resp.headers["content-type"].startswith("application/xml") def test_sitemap_xml_contains_routes(self): client = self._client() resp = client.get("/api/sitemap/sitemap.xml") body = resp.text for path in ["/", "/about", "/schedule", "/events", "/contact"]: assert f"https://kmountainflower.org{path}" in body def test_robots_txt_status(self): client = self._client() resp = client.get("/api/sitemap/robots.txt") assert resp.status_code == 200 def test_robots_txt_content_type(self): client = self._client() resp = client.get("/api/sitemap/robots.txt") assert resp.headers["content-type"].startswith("text/plain") def test_robots_txt_contains_rules(self): client = self._client() resp = client.get("/api/sitemap/robots.txt") body = resp.text assert "User-agent: *" in body assert "Disallow: /admin" in body assert "Disallow: /login" in body assert "Sitemap: https://kmountainflower.org/sitemap.xml" in body def test_regenerate_requires_auth(self): client = self._client() resp = client.post("/api/sitemap/regenerate") assert resp.status_code in (401, 403)