djangocms_blog/tests/test_wizards.py

80 lines
3.2 KiB
Python
Raw Normal View History

2015-10-25 15:22:13 +00:00
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
2015-10-25 17:56:00 +00:00
import sys
2015-10-25 15:22:13 +00:00
from .base import BaseTest
class WizardTest(BaseTest):
2015-10-25 17:56:00 +00:00
def setUp(self):
try:
from cms.wizards.wizard_pool import wizard_pool
delete = [
'djangocms_blog',
'djangocms_blog.cms_wizards',
]
for module in delete:
if module in sys.modules:
del sys.modules[module]
wizard_pool._reset()
except ImportError:
# Not in django CMS 3.2+, no cleanup needed
pass
2016-03-27 17:25:01 +00:00
super(WizardTest, self).setUp()
2015-10-25 17:56:00 +00:00
2015-10-25 15:22:13 +00:00
def test_wizard(self):
"""
Test that Blog wizard is present and contains all items
"""
from cms.wizards.wizard_pool import wizard_pool
self.get_pages()
titles = [entry.title for entry in wizard_pool.get_entries()]
self.assertTrue('New Blog' in titles)
self.assertTrue('New Article' in titles)
2015-10-25 17:14:19 +00:00
def test_wizard_init(self):
2015-11-26 23:14:33 +00:00
from cms.utils.permissions import current_user
2015-10-25 17:14:19 +00:00
from cms.wizards.wizard_pool import wizard_pool
from djangocms_blog.models import Post
self.get_pages()
2015-11-25 09:34:50 +00:00
with current_user(self.user_staff):
wizs = [entry for entry in wizard_pool.get_entries() if entry.model == Post]
for index, wiz in enumerate(wizs):
app_config = self.app_config_1.pk if wiz.title == 'New Blog' else self.app_config_2.pk
form = wiz.form()
self.assertTrue(form.initial.get('app_config', False), app_config)
self.assertTrue(form.fields['app_config'].widget.attrs['disabled'])
2015-10-25 17:14:19 +00:00
2015-11-25 09:34:50 +00:00
form = wiz.form(data={
'1-title': 'title{0}'.format(index),
'1-abstract': 'abstract{0}'.format(index),
'1-categories': [self.category_1.pk],
}, prefix=1)
self.assertEqual(form.default_appconfig, app_config)
self.assertTrue(form.is_valid())
2016-02-26 22:48:37 +00:00
self.assertEqual(form.cleaned_data['app_config'].pk, app_config)
2015-11-25 09:34:50 +00:00
instance = form.save()
self.assertEqual(instance.author, self.user_staff)
with self.settings(BLOG_AUTHOR_DEFAULT='normal'):
for index, wiz in enumerate(wizs):
2015-11-26 06:54:20 +00:00
app_config = self.app_config_1.pk if wiz.title == 'New Blog' else self.app_config_2.pk
2015-11-25 09:34:50 +00:00
form = wiz.form(data={
'1-title': 'title-2{0}'.format(index),
'1-abstract': 'abstract-2{0}'.format(index),
'1-categories': [self.category_1.pk],
}, prefix=1)
2015-11-26 06:54:20 +00:00
self.assertEqual(form.default_appconfig, app_config)
self.assertTrue(form.is_valid())
2016-02-26 22:48:37 +00:00
self.assertEqual(form.cleaned_data['app_config'].pk, app_config)
2015-11-25 09:34:50 +00:00
instance = form.save()
self.assertEqual(instance.author, self.user_normal)
2015-10-25 17:14:19 +00:00
def test_wizard_import(self):
2015-10-31 10:50:59 +00:00
# The following import should not fail in any django CMS version
2016-06-05 22:08:28 +00:00
pass