foxhole/tests/test_main.py

27 lines
900 B
Python
Raw Normal View History

2023-04-03 03:50:59 +02:00
#!/usr/bin/env python3
2023-04-03 09:16:46 +02:00
import pytest
2023-04-03 03:50:59 +02:00
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
2023-04-03 09:16:46 +02:00
from app import activitypub as ap
from app.config import AP_CONTENT_TYPE
2023-04-03 03:50:59 +02:00
2023-04-03 09:16:46 +02:00
_ACCEPTED_AP_HEADERS = [
"application/activity+json",
"application/activity+json; charset=utf-8",
"application/ld+json",
'application/ld+json; profile="https://www.w3.org/ns/activitystreams"',
]
2023-04-03 03:50:59 +02:00
def test_index__html(client: TestClient):
response = client.get("/")
assert response.status_code == 200
2023-04-03 09:16:46 +02:00
assert response.headers["content-type"] == "application/json"
@pytest.mark.parametrize("accept", _ACCEPTED_AP_HEADERS)
def test_index__ap(db: Session, client: TestClient, accept: str):
response = client.get("/", headers={"Accept": accept})
assert response.status_code == 200
assert response.headers["content-type"] == AP_CONTENT_TYPE
assert response.json() == ap.ME