general: add compatibility with Django 1.8 (#10288)
This commit is contained in:
parent
93603bc96d
commit
9f62013af4
|
@ -29,11 +29,13 @@ class RegieListView(ListView):
|
|||
|
||||
class RegieCreateView(CreateView):
|
||||
model = Regie
|
||||
fields = '__all__'
|
||||
success_url = reverse_lazy('lingo-manager-regie-list')
|
||||
|
||||
|
||||
class RegieUpdateView(UpdateView):
|
||||
model = Regie
|
||||
fields = '__all__'
|
||||
success_url = reverse_lazy('lingo-manager-regie-list')
|
||||
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
from django import forms
|
||||
from django.conf import settings
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.template.loader import find_template, TemplateDoesNotExist
|
||||
from django.template.loader import get_template, TemplateDoesNotExist
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from combo.data.models import Page
|
||||
|
@ -36,7 +36,7 @@ class PageForm(forms.ModelForm):
|
|||
|
||||
def template_exists(self, template):
|
||||
try:
|
||||
find_template(settings.COMBO_PUBLIC_TEMPLATES[template].get('template'))
|
||||
get_template(settings.COMBO_PUBLIC_TEMPLATES[template].get('template'))
|
||||
except TemplateDoesNotExist:
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -20,6 +20,7 @@ import datetime
|
|||
|
||||
from django import template
|
||||
from django.template import Context, RequestContext
|
||||
from django.template.base import TOKEN_BLOCK, TOKEN_VAR
|
||||
|
||||
from combo.public.menu import get_menu_context
|
||||
from combo.utils import NothingInCacheException
|
||||
|
@ -67,14 +68,14 @@ def skeleton_extra_placeholder(parser, token):
|
|||
token = tokens_copy.pop(0)
|
||||
if token.contents == 'end_skeleton_extra_placeholder':
|
||||
break
|
||||
if token.token_type == template.TOKEN_VAR:
|
||||
if token.token_type == TOKEN_VAR:
|
||||
text.append('{{')
|
||||
elif token.token_type == template.TOKEN_BLOCK:
|
||||
elif token.token_type == TOKEN_BLOCK:
|
||||
text.append('{%')
|
||||
text.append(token.contents)
|
||||
if token.token_type == template.TOKEN_VAR:
|
||||
if token.token_type == TOKEN_VAR:
|
||||
text.append('}}')
|
||||
elif token.token_type == template.TOKEN_BLOCK:
|
||||
elif token.token_type == TOKEN_BLOCK:
|
||||
text.append('%}')
|
||||
|
||||
nodelist = parser.parse(('end_skeleton_extra_placeholder',))
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
import pytest
|
||||
|
||||
import django_webtest
|
||||
|
||||
@pytest.fixture
|
||||
def app(request):
|
||||
wtm = django_webtest.WebTestMixin()
|
||||
wtm._patch_settings()
|
||||
request.addfinalizer(wtm._unpatch_settings)
|
||||
return django_webtest.DjangoTestApp()
|
|
@ -28,6 +28,7 @@ def test_media():
|
|||
# to prevent error in Models metaclass as the current module is not
|
||||
# in a registered applicatoin
|
||||
app_label = 'data'
|
||||
abstract = True
|
||||
cells = [TextCelleWithMedia() for i in range(3)]
|
||||
assert unicode(sum((cell.media for cell in cells), Media())) == u'<script type="text/javascript" src="/static/coincoin.js"></script>'
|
||||
|
||||
|
|
|
@ -24,14 +24,14 @@ def login(app, username='admin', password='admin'):
|
|||
assert resp.status_int == 302
|
||||
return app
|
||||
|
||||
def test_access(admin_user):
|
||||
app = login(TestApp(get_wsgi_application()))
|
||||
def test_access(app, admin_user):
|
||||
app = login(app)
|
||||
resp = app.get('/manage/', status=200)
|
||||
assert '/manage/lingo/' in resp.body
|
||||
|
||||
def test_add_regie(admin_user):
|
||||
def test_add_regie(app, admin_user):
|
||||
Regie.objects.all().delete()
|
||||
app = login(TestApp(get_wsgi_application()))
|
||||
app = login(app)
|
||||
resp = app.get('/manage/lingo/regies/', status=200)
|
||||
resp = resp.click('New')
|
||||
resp.forms[0]['label'] = 'Test'
|
||||
|
@ -44,9 +44,9 @@ def test_add_regie(admin_user):
|
|||
regie = Regie.objects.all()[0]
|
||||
assert regie.label == 'Test'
|
||||
|
||||
def test_edit_regie(admin_user):
|
||||
test_add_regie(admin_user)
|
||||
app = login(TestApp(get_wsgi_application()))
|
||||
def test_edit_regie(app, admin_user):
|
||||
test_add_regie(app, admin_user)
|
||||
app = login(app)
|
||||
resp = app.get('/manage/lingo/regies/', status=200)
|
||||
resp = resp.click('Test')
|
||||
resp.forms[0]['description'] = 'other description'
|
||||
|
@ -56,9 +56,9 @@ def test_edit_regie(admin_user):
|
|||
regie = Regie.objects.all()[0]
|
||||
assert regie.description == 'other description'
|
||||
|
||||
def test_delete_regie(admin_user):
|
||||
test_add_regie(admin_user)
|
||||
app = login(TestApp(get_wsgi_application()))
|
||||
def test_delete_regie(app, admin_user):
|
||||
test_add_regie(app, admin_user)
|
||||
app = login(app)
|
||||
resp = app.get('/manage/lingo/regies/', status=200)
|
||||
resp = resp.click('Test')
|
||||
resp = resp.click('Delete')
|
||||
|
|
|
@ -30,19 +30,18 @@ def login(app, username='admin', password='admin'):
|
|||
assert resp.status_int == 302
|
||||
return app
|
||||
|
||||
def test_unlogged_access():
|
||||
def test_unlogged_access(app):
|
||||
# connect while not being logged in
|
||||
app = TestApp(application)
|
||||
assert app.get('/manage/', status=302).location == 'http://localhost:80/login/?next=/manage/'
|
||||
|
||||
def test_access(admin_user):
|
||||
app = login(TestApp(application))
|
||||
def test_access(app, admin_user):
|
||||
app = login(app)
|
||||
resp = app.get('/manage/', status=200)
|
||||
assert 'Pages' in resp.body
|
||||
assert "This site doesn't have any page yet." in resp.body
|
||||
|
||||
def test_add_page(admin_user):
|
||||
app = login(TestApp(application))
|
||||
def test_add_page(app, admin_user):
|
||||
app = login(app)
|
||||
resp = app.get('/manage/', status=200)
|
||||
resp = resp.click('New')
|
||||
assert resp.forms[0]['title'].value == 'Home' # default title for first page
|
||||
|
@ -50,22 +49,22 @@ def test_add_page(admin_user):
|
|||
resp = resp.forms[0].submit()
|
||||
assert resp.location == 'http://localhost:80/manage/pages/1/'
|
||||
|
||||
def test_add_second_page(admin_user):
|
||||
def test_add_second_page(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one')
|
||||
page.save()
|
||||
app = login(TestApp(application))
|
||||
app = login(app)
|
||||
resp = app.get('/manage/', status=200)
|
||||
resp = resp.click('New')
|
||||
# assert there's no defaul title or slug for the second page
|
||||
assert resp.forms[0]['title'].value == ''
|
||||
assert resp.forms[0]['slug'].value == ''
|
||||
|
||||
def test_delete_page(admin_user):
|
||||
def test_delete_page(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one', template_name='standard')
|
||||
page.save()
|
||||
app = login(TestApp(application))
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
resp = resp.click('delete')
|
||||
assert 'Confirm Deletion' in resp.body
|
||||
|
@ -73,21 +72,21 @@ def test_delete_page(admin_user):
|
|||
assert resp.location == 'http://localhost:80/manage/'
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
def test_export_page(admin_user):
|
||||
def test_export_page(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one', template_name='standard')
|
||||
page.save()
|
||||
app = login(TestApp(application))
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
resp = resp.click('export')
|
||||
assert resp.headers['content-type'] == 'application/json'
|
||||
assert resp.json.get('fields').get('slug') == 'one'
|
||||
|
||||
def test_add_edit_cell(admin_user):
|
||||
def test_add_edit_cell(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='One', slug='one', template_name='standard')
|
||||
page.save()
|
||||
app = login(TestApp(application))
|
||||
app = login(app)
|
||||
resp = app.get('/manage/pages/%s/' % page.id)
|
||||
# click on first button link, this should add a text cell
|
||||
resp = app.get(resp.html.find('button').get('data-add-url'))
|
||||
|
@ -118,13 +117,13 @@ def test_add_edit_cell(admin_user):
|
|||
assert resp.forms[0]['c%s-text' % cells[0].get_reference()].value == 'World Hello'
|
||||
|
||||
|
||||
def test_logout(admin_user):
|
||||
app = login(TestApp(application))
|
||||
def test_logout(app, admin_user):
|
||||
app = login(app)
|
||||
app.get('/logout/')
|
||||
assert app.get('/manage/', status=302).location == 'http://localhost:80/login/?next=/manage/'
|
||||
|
||||
def test_asset_management(admin_user):
|
||||
app = login(TestApp(application))
|
||||
def test_asset_management(app, admin_user):
|
||||
app = login(app)
|
||||
resp = app.get('/manage/assets/')
|
||||
assert 'have any asset yet.' in resp.body
|
||||
|
||||
|
|
|
@ -10,17 +10,15 @@ pytestmark = pytest.mark.django_db
|
|||
|
||||
from test_manager import admin_user, login
|
||||
|
||||
def test_missing_index():
|
||||
def test_missing_index(app):
|
||||
Page.objects.all().delete()
|
||||
app = TestApp(application)
|
||||
resp = app.get('/', status=200)
|
||||
assert 'Welcome' in resp.body
|
||||
|
||||
def test_index():
|
||||
def test_index(app):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='Home', slug='index', template_name='standard')
|
||||
page.save()
|
||||
app = TestApp(application)
|
||||
resp = app.get('/index', status=301)
|
||||
assert resp.location == 'http://localhost:80/'
|
||||
resp = app.get('/', status=200)
|
||||
|
@ -28,38 +26,35 @@ def test_index():
|
|||
# check {% now %} inside a skeleton_extra_placeholder is interpreted
|
||||
assert str(datetime.datetime.now().year) in resp.body
|
||||
|
||||
def test_page_contents():
|
||||
def test_page_contents(app):
|
||||
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_contents_unlogged_only(admin_user):
|
||||
def test_page_contents_unlogged_only(app, admin_user):
|
||||
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,
|
||||
restricted_to_unlogged=True)
|
||||
cell.save()
|
||||
app = TestApp(application)
|
||||
resp = app.get('/', status=200)
|
||||
assert 'Foobar' in resp.body
|
||||
|
||||
app = login(TestApp(application))
|
||||
app = login(app)
|
||||
resp = app.get('/', status=200)
|
||||
assert not 'Foobar' in resp.body
|
||||
|
||||
def test_page_footer_acquisition():
|
||||
def test_page_footer_acquisition(app):
|
||||
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
|
||||
|
||||
|
@ -70,36 +65,33 @@ def test_page_footer_acquisition():
|
|||
resp = app.get('/second/', status=200)
|
||||
assert 'BARFOO' in resp.body
|
||||
|
||||
def test_page_redirect():
|
||||
def test_page_redirect(app):
|
||||
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():
|
||||
def test_page_private_unlogged(app):
|
||||
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):
|
||||
def test_page_private_logged_in(app, admin_user):
|
||||
Page.objects.all().delete()
|
||||
page = Page(title='Home', slug='index', template_name='standard', public=False)
|
||||
page.save()
|
||||
app = login(TestApp(application))
|
||||
app = login(app)
|
||||
resp = app.get('/', status=200)
|
||||
|
||||
def test_page_skeleton():
|
||||
def test_page_skeleton(app):
|
||||
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'))
|
||||
|
@ -129,7 +121,7 @@ def test_page_skeleton():
|
|||
# check {% now %} inside a skeleton_extra_placeholder is not interpreted
|
||||
assert '{%now' in resp.body
|
||||
|
||||
def test_subpage_location():
|
||||
def test_subpage_location(app):
|
||||
Page.objects.all().delete()
|
||||
|
||||
page_index = Page(title='Home Page', slug='index', template_name='standard')
|
||||
|
@ -154,7 +146,6 @@ def test_subpage_location():
|
|||
template_name='standard', parent=page)
|
||||
page.save()
|
||||
|
||||
app = TestApp(application)
|
||||
resp = app.get('/', status=200)
|
||||
assert 'Home Page' in resp.body
|
||||
|
||||
|
@ -177,8 +168,7 @@ def test_subpage_location():
|
|||
resp = app.get('/second/child-second/grand-child-second/', status=200)
|
||||
assert 'Grand child of second' in resp.body
|
||||
|
||||
def test_404():
|
||||
def test_404(app):
|
||||
Page.objects.all().delete()
|
||||
app = TestApp(application)
|
||||
resp = app.get('/foobar/', status=404)
|
||||
assert "This page doesn't exist" in resp.body
|
||||
|
|
Loading…
Reference in New Issue