lemoncurry/wellknowns/tests/views/host_meta.py

27 lines
849 B
Python
Raw Permalink Normal View History

import json
from lxml import etree
import pytest
@pytest.mark.django_db
def test_host_meta_json(client):
2023-08-10 02:52:37 -04:00
res = client.get("/.well-known/host-meta.json")
assert res.status_code == 200
2023-08-10 02:52:37 -04:00
assert res["Content-Type"] == "application/json"
meta = json.loads(res.content)
2023-08-10 02:52:37 -04:00
assert meta.keys() == {"links", "subject"}
assert meta["subject"] == "https://example.com"
assert len(meta["links"]) == 13
@pytest.mark.django_db
def test_host_meta_xml(client):
2023-08-10 02:52:37 -04:00
res = client.get("/.well-known/host-meta")
assert res.status_code == 200
2023-08-10 02:52:37 -04:00
assert res["Content-Type"] == "application/xrd+xml"
root = etree.XML(res.content)
2023-08-10 02:52:37 -04:00
ns = "{http://docs.oasis-open.org/ns/xri/xrd-1.0}"
assert root.tag == (ns + "XRD")
assert root.findtext(ns + "Subject") == "https://example.com"
assert len(root.findall(ns + "Link")) == 13