style: add messages only if requested in styles demo page(#62172)
This commit is contained in:
parent
bed3ff7ed8
commit
dd74d196f6
|
@ -375,8 +375,14 @@ class StyleDemoPage:
|
|||
def __init__(self, request):
|
||||
self.request = request
|
||||
self.template_name = request.GET.get('template') or 'standard'
|
||||
self.with_messages = request.GET.get('with_messages') or False
|
||||
|
||||
def __enter__(self):
|
||||
if self.with_messages:
|
||||
messages.success(self.request, _('Success notice'))
|
||||
messages.info(self.request, _('Info notice'))
|
||||
messages.warning(self.request, _('Warning notice'))
|
||||
messages.error(self.request, _('Error notice'))
|
||||
self.page = Page(public=False, title=_('Style Demo'))
|
||||
self.page.template_name = self.template_name
|
||||
self.page.save()
|
||||
|
@ -416,9 +422,13 @@ class StyleDemoPage:
|
|||
attr += ' selected="selected"'
|
||||
options_html.append('<option %s>%s</option>' % (attr, template_dict['name']))
|
||||
cell.text = '''<form><select name="template">%s</select>
|
||||
<button>%s</button></form>''' % (
|
||||
<button>%s</button>
|
||||
<button name="with_messages" value="on">%s</button>
|
||||
</form>
|
||||
''' % (
|
||||
'\n'.join(options_html),
|
||||
_('Select'),
|
||||
_('Add messages'),
|
||||
)
|
||||
cell.save()
|
||||
|
||||
|
@ -441,10 +451,6 @@ class StyleDemoPage:
|
|||
def style(request):
|
||||
if not settings.DEBUG:
|
||||
raise Http404()
|
||||
messages.success(request, _('Success notice'))
|
||||
messages.info(request, _('Info notice'))
|
||||
messages.warning(request, _('Warning notice'))
|
||||
messages.error(request, _('Error notice'))
|
||||
|
||||
with transaction.atomic():
|
||||
with StyleDemoPage(request) as page:
|
||||
|
|
|
@ -571,11 +571,20 @@ def test_style_demo(app, admin_user):
|
|||
app = login(app)
|
||||
with override_settings(DEBUG=True):
|
||||
resp = app.get('/__style__/', status=200)
|
||||
assert 'class="success"' not in resp.text
|
||||
assert 'class="info"' not in resp.text
|
||||
assert 'class="warning"' not in resp.text
|
||||
assert 'class="error"' not in resp.text
|
||||
assert 'Lorem ipsum' in resp.text
|
||||
assert TextCell.objects.count() == 0
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
resp = app.get('/__style__/?template=standard-sidebar', status=200)
|
||||
resp = app.get('/__style__/?template=standard-sidebar&with_messages=on', status=200)
|
||||
assert 'class="success"' in resp.text
|
||||
assert 'class="info"' in resp.text
|
||||
assert 'class="warning"' in resp.text
|
||||
assert 'class="error"' in resp.text
|
||||
assert 'Lorem ipsum' in resp.text
|
||||
assert 'links-list' in resp.text
|
||||
assert Page.objects.count() == 0
|
||||
|
||||
|
|
Loading…
Reference in New Issue