Add support for tests that use django.test.Client and that require a database, and use this support to test some of the wellknowns.views modules
This commit is contained in:
parent
380afe9831
commit
cbc24d4774
6 changed files with 44 additions and 1 deletions
4
lemoncurry/settings/test.py
Normal file
4
lemoncurry/settings/test.py
Normal file
|
@ -0,0 +1,4 @@
|
|||
from .base import *
|
||||
|
||||
ALLOWED_HOSTS = ['*']
|
||||
SECURE_SSL_REDIRECT = False
|
|
@ -1,3 +1,3 @@
|
|||
[pytest]
|
||||
DJANGO_SETTINGS_MODULE = lemoncurry.settings.dev
|
||||
DJANGO_SETTINGS_MODULE = lemoncurry.settings.test
|
||||
python_files = tests/*.py
|
||||
|
|
0
wellknowns/tests/__init__.py
Normal file
0
wellknowns/tests/__init__.py
Normal file
0
wellknowns/tests/views/__init__.py
Normal file
0
wellknowns/tests/views/__init__.py
Normal file
26
wellknowns/tests/views/host_meta.py
Normal file
26
wellknowns/tests/views/host_meta.py
Normal file
|
@ -0,0 +1,26 @@
|
|||
import json
|
||||
from lxml import etree
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_host_meta_json(client):
|
||||
res = client.get('/.well-known/host-meta.json')
|
||||
assert res.status_code == 200
|
||||
assert res['Content-Type'] == 'application/json'
|
||||
meta = json.loads(res.content)
|
||||
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):
|
||||
res = client.get('/.well-known/host-meta')
|
||||
assert res.status_code == 200
|
||||
assert res['Content-Type'] == 'application/xrd+xml'
|
||||
root = etree.XML(res.content)
|
||||
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
|
13
wellknowns/tests/views/static.py
Normal file
13
wellknowns/tests/views/static.py
Normal file
|
@ -0,0 +1,13 @@
|
|||
from ...views import static
|
||||
|
||||
|
||||
def test_redirect_to_static(rf):
|
||||
res = static.redirect_to_static('abcd')(rf.get('/'))
|
||||
assert res.status_code == 302
|
||||
assert res.url == '/static/wellknowns/abcd'
|
||||
|
||||
|
||||
def test_keybase(rf):
|
||||
res = static.keybase(rf.get('/.well-knowns/keybase.txt'))
|
||||
assert res.status_code == 302
|
||||
assert res.url == '/static/wellknowns/keybase.txt'
|
Loading…
Reference in a new issue