Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Merge e54bfff into ec1e89f
Browse files Browse the repository at this point in the history
  • Loading branch information
czpython committed May 23, 2016
2 parents ec1e89f + e54bfff commit 173a970
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
18 changes: 16 additions & 2 deletions aldryn_faq/cms_wizards.py
Expand Up @@ -145,7 +145,21 @@ def save(self, commit=True):
# If 'content' field has value, create a TextPlugin with same and add
# it to the PlaceholderField
answer = clean_html(self.cleaned_data.get('answer', ''), False)
content_plugin = get_cms_setting('WIZARD_CONTENT_PLUGIN')

try:
# CMS >= 3.3.x
content_plugin = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN')
except KeyError:
# CMS <= 3.2.x
content_plugin = get_cms_setting('WIZARD_CONTENT_PLUGIN')

try:
# CMS >= 3.3.x
content_field = get_cms_setting('PAGE_WIZARD_CONTENT_PLUGIN_BODY')
except KeyError:
# CMS <= 3.2.x
content_field = get_cms_setting('WIZARD_CONTENT_PLUGIN_BODY')

if answer and permissions.has_plugin_permission(
self.user, content_plugin, 'add'):

Expand All @@ -160,7 +174,7 @@ def save(self, commit=True):
'placeholder': question.answer,
'plugin_type': content_plugin,
'language': self.language_code,
get_cms_setting('WIZARD_CONTENT_PLUGIN_BODY'): answer,
content_field: answer,
}
add_plugin(**plugin_kwarg)

Expand Down
57 changes: 57 additions & 0 deletions aldryn_faq/tests/test_wizards.py
@@ -0,0 +1,57 @@
# -*- coding: utf-8 -*-
import sys

from distutils.version import LooseVersion

import cms

from djangocms_helper.utils import create_user

from aldryn_faq.cms_wizards import CreateFaqQuestionForm

from .test_base import AldrynFaqTest


if sys.version_info < (2, 7):
import unittest2 as unittest
else:
import unittest

# The CMS wizard system was introduced in 3.2.0
CMS_3_2 = LooseVersion(cms.__version__) >= LooseVersion('3.2.0')


@unittest.skipUnless(CMS_3_2, "No wizard support in CMS < 3.2")
class TestFAQWizard(AldrynFaqTest):

def setUp(self):
super(TestFAQWizard, self).setUp()
username = 'admin_user'
password = 'test'
self.admin_user = create_user(
username=username,
email='test@example.com',
password=password,
is_superuser=True,
)
self.client.login(username=username, password=password)

def test_question_wizard(self):
data = {
'title': 'Where are we?',
'answer': 'Here.',
'answer_text': '<p>Interesting question..</p>',
'category': self.category1.pk,
}
form = CreateFaqQuestionForm(
data=data,
wizard_language='en',
wizard_user=self.admin_user,
)
self.assertTrue(form.is_valid())
question = form.save()

url = question.get_absolute_url('en')
response = self.client.get(url)
self.assertContains(response, 'Where are we?', status_code=200)
self.assertContains(response, 'Here.', status_code=200)

0 comments on commit 173a970

Please sign in to comment.