combo/tests/test_public.py

102 lines
3.5 KiB
Python

from webtest import TestApp
import pytest
import urllib
from combo.wsgi import application
from combo.data.models import Page, CellBase, TextCell
pytestmark = pytest.mark.django_db
from test_manager import admin_user, login
def test_missing_index():
Page.objects.all().delete()
app = TestApp(application)
resp = app.get('/', status=200)
assert 'Welcome' in resp.body
def test_index():
Page.objects.all().delete()
page = Page(title='Home', slug='index', template_name='standard')
page.save()
app = TestApp(application)
resp = app.get('/index', status=200)
resp = app.get('/', status=200)
def test_page_contents():
Page.objects.all().delete()
page = Page(title='Home', slug='index', template_name='standard')
page.save()
cell = TextCell(page=page, placeholder='content', text='Foobar', order=0)
cell.save()
app = TestApp(application)
resp = app.get('/', status=200)
assert 'Foobar' in resp.body
def test_page_footer_acquisition():
Page.objects.all().delete()
page = Page(title='Home', slug='index', template_name='standard')
page.save()
cell = TextCell(page=page, placeholder='footer', text='BARFOO', order=0)
cell.save()
app = TestApp(application)
resp = app.get('/', status=200)
assert 'BARFOO' in resp.body
page = Page(title='Second', slug='second', template_name='standard')
page.save()
resp = app.get('/second', status=200)
assert 'BARFOO' in resp.body
def test_page_redirect():
Page.objects.all().delete()
page = Page(title='Elsewhere', slug='elsewhere', template_name='standard',
redirect_url='http://example.net')
page.save()
app = TestApp(application)
resp = app.get('/elsewhere', status=302)
assert resp.location == 'http://example.net'
def test_page_private_unlogged():
Page.objects.all().delete()
page = Page(title='Home', slug='index', template_name='standard', public=False)
page.save()
app = TestApp(application)
resp = app.get('/', status=302)
assert resp.location == 'http://localhost:80/login/?next=/'
def test_page_private_logged_in(admin_user):
Page.objects.all().delete()
page = Page(title='Home', slug='index', template_name='standard', public=False)
page.save()
app = login(TestApp(application))
resp = app.get('/', status=200)
def test_page_skeleton():
Page.objects.all().delete()
page = Page(title='Elsewhere', slug='elsewhere', template_name='standard',
redirect_url='http://example.net/foo/')
page.save()
app = TestApp(application)
# url prefix match
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.net/foo/bar'))
assert '{% block content %}{% endblock %}' in resp.body
assert '{% block footer %}{% endblock %}' in resp.body
# url netloc match
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.net'))
assert '{% block content %}{% endblock %}' in resp.body
assert '{% block footer %}{% endblock %}' in resp.body
# no match
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.com/foo/bar'), status=403)
# check with a footer cell
cell = TextCell(page=page, placeholder='footer', text='Foobar', order=0)
cell.save()
resp = app.get('/__skeleton__/?source=%s' % urllib.quote('http://example.net'))
assert '{% block content %}{% endblock %}' in resp.body
assert not '{% block footer %}{% endblock %}' in resp.body
assert 'Foobar' in resp.body