test_middlewares.py 906 B

12345678910111213141516171819202122232425262728293031323334
  1. from fastapi.testclient import TestClient
  2. from app.main import app
  3. client = TestClient(app)
  4. def test_case_sensitive_headers_preserves_case():
  5. response = client.get(
  6. "/ping",
  7. headers={"X-Custom-Header": "value", "User-Agent": "test"},
  8. )
  9. assert response.status_code == 200
  10. def test_case_sensitive_headers_no_raw_headers():
  11. response = client.get("/ping", headers={})
  12. assert response.status_code == 200
  13. def test_case_sensitive_headers_post_with_content_type():
  14. response = client.post(
  15. "/api/v1/visit",
  16. json={"url": "https://example.com"},
  17. headers={"X-Custom-Header": "value", "Content-Type": "application/json"},
  18. )
  19. assert response.status_code in (200, 422)
  20. def test_valid_headers_filtering():
  21. response = client.get(
  22. "/api/v1/ping",
  23. headers={"User-Agent": "test"},
  24. )
  25. assert response.status_code == 200