Files
Alex_Portfolio/backend/test_offline.py
T

48 lines
2.2 KiB
Python

"""Verify the intentional shutdown blocks content and storage side effects."""
import json
import unittest
from unittest.mock import patch
from fastapi.testclient import TestClient
from backend import main
class OfflineTests(unittest.TestCase):
def test_all_routes_and_methods_return_blank_gone(self):
paths = [
"/", "/experience", "/blog/example", "/api/profile",
"/api/experience", "/api/posts", "/api/health", "/api/resume",
"/api/auth/login", "/api/contact", "/api/cron/media-cleanup",
"/api/resume?v=resume-v25", "/resumes/resume-v25.pdf",
"/api/uploads/" + "a" * 32, "/alexander-herlan.png",
"/assets/old.js", "/docs", "/openapi.json", "/missing",
]
with patch.object(main, "get_supabase") as storage, \
patch.object(main, "read_data") as data, \
patch.object(main, "deliver_contact_email") as email, \
patch.object(main.media_cleanup, "cleanup_pending") as cleanup, \
TestClient(main.app) as client:
for method in ("GET", "HEAD", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"):
for path in paths:
with self.subTest(method=method, path=path):
response = client.request(method, path)
self.assertEqual(response.status_code, 410)
expected = b"<!doctype html><html><head><title></title></head><body></body></html>"
self.assertEqual(response.content, b"" if method == "HEAD" else expected)
self.assertEqual(response.headers["cache-control"], "no-store")
self.assertEqual(response.headers["x-robots-tag"], "noindex, nofollow")
storage.assert_not_called()
data.assert_not_called()
email.assert_not_called()
cleanup.assert_not_called()
def test_vercel_has_no_static_bypass_or_scheduled_jobs(self):
config = json.loads((main.PROJECT_DIR / "vercel.json").read_text(encoding="utf-8"))
self.assertEqual(config["routes"], [{"src": "/.*", "dest": "/api/index.py"}])
self.assertEqual(config["crons"], [])
if __name__ == "__main__":
unittest.main()