61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
#!/usr/bin/env python3
|
|
import pytest
|
|
import httpx
|
|
import respx
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy.orm import Session
|
|
from app import activitypub as ap
|
|
from app.config import AP_CONTENT_TYPE
|
|
from tests.utils import build_remote_actor
|
|
|
|
|
|
_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"',
|
|
]
|
|
|
|
|
|
def test_index__html(client: TestClient):
|
|
response = client.get("/")
|
|
assert response.status_code == 200
|
|
assert response.headers["content-type"].startswith("text/html")
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_follow_only_status(
|
|
client: TestClient,
|
|
respx_mock: respx.MockRouter,
|
|
) -> None:
|
|
# build test actor
|
|
ra = build_remote_actor()
|
|
remote_ap_id = ra.ap_id # type: ignore
|
|
|
|
# mock request
|
|
respx_mock.get(remote_ap_id).mock(
|
|
return_value=httpx.Response(200,json=ra.ap_actor))
|
|
respx_mock.post(remote_ap_id + "/inbox").mock(
|
|
return_value=httpx.Response(202))
|
|
|
|
|
|
response = client.post(
|
|
"/outbox",
|
|
headers={"Authorization": "Basic test-token"},
|
|
content='{"visibility": "followers-only","content": "note content"}'
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
# And the Note was not show in the index
|
|
|
|
indext_content = client.get("/").text
|
|
assert "note content" not in indext_content
|