-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_misc_api.py
36 lines (28 loc) · 1.14 KB
/
test_misc_api.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from urllib.parse import quote
from django.urls import reverse
import pytest
@pytest.mark.django_db
def test_rss_api(client, processed_document):
response = client.get(
"/api/page/?document={}&format=rss".format(processed_document.pk)
)
content = response.content.decode("utf-8")
for i in range(1, processed_document.num_pages + 1):
assert (
"<title>{} (p. {})</title>".format(processed_document.title, i) in content
)
@pytest.mark.django_db
def test_oembed_api(client, processed_document, settings):
settings.SITE_URL = "https://example.com"
oembed_url = reverse("api:document-oembed") + "?url={}".format(
quote(processed_document.get_absolute_domain_url())
)
response = client.get(oembed_url + "&format=xml")
# content negotiation fails already for format XML
assert response.status_code == 404
response = client.get(oembed_url)
data = response.json()
assert data["version"] == "1.0"
assert data["title"] == processed_document.title
assert data["html"].startswith("<iframe")
assert processed_document.get_absolute_domain_embed_url() in data["html"]