Repository URL to install this package:
Version:
0.2.0a3 ▾
|
dj-kaos
/
test_pad.py
|
---|
import pytest
from django.http import Http404
from django.urls import resolve
from dj_kaos.contrib.pad import utils, views, settings as app_settings
@pytest.fixture # (params=['', 'app/'])
def pad_path(request):
# settings.PAD_URL = request.param
# django.setup()
return ''
def test_serve_file_view(rf, pad_path):
request = rf.get(f'/{pad_path}home')
response = views.serve_file(request, filename='index.html')
assert response.status_code == 200
assert list(response.streaming_content)[0] == (app_settings.PAD_ROOT / 'index.html').read_bytes()
def test_redirect_static_view(rf, pad_path):
request = rf.get(f'/{pad_path}static/js/main.f9d654a7.js')
response = views.redirect_static(request, resource='main.f9d654a7.js')
assert response.status_code == 302
assert response.url == f'/static/main.f9d654a7.js'
def test_urls(rf, pad_path):
assert resolve(f'/{pad_path}static/main.f9d654a7.js').func == views.redirect_static
assert resolve(f'/{pad_path}favicon.ico').func == views.serve_file
assert resolve(f'/{pad_path}').func == views.serve_file
assert resolve(f'/{pad_path}path/').func == views.serve_file
with pytest.raises(Http404):
request = rf.get(f'/{pad_path}not-found.ico')
resolver = resolve(f'/{pad_path}not-found.ico')
resolver.func(request, **resolver.kwargs)
def test_get_dont_match_prefix_regex():
assert utils.get_dont_match_prefix_regex(['abc', 'def'], 'ghi') == '^(?!abc|def)^ghi'
assert utils.get_dont_match_prefix_regex(['abc', 'def']) == '^(?!abc|def)'