Skip to content

Commit

Permalink
Merge branch 'develop' of https://github.com/divio/django-cms into fe…
Browse files Browse the repository at this point in the history
…ature-moderation
  • Loading branch information
adaptivelogic committed Oct 4, 2012
2 parents 515e321 + f23a2e6 commit 7f56291
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 12 deletions.
24 changes: 23 additions & 1 deletion cms/admin/placeholderadmin.py
Expand Up @@ -202,7 +202,29 @@ def edit_plugin(self, request, plugin_id):
post_request = request.POST.copy()
post_request['_continue'] = True
request.POST = post_request


if request.POST.get("_cancel", False):
# cancel button was clicked
context = {
'CMS_MEDIA_URL': settings.CMS_MEDIA_URL,
'plugin': cms_plugin,
'is_popup': True,
'name': unicode(cms_plugin),
"type": cms_plugin.get_plugin_name(),
'plugin_id': plugin_id,
'icon': force_escape(escapejs(cms_plugin.get_instance_icon_src())),
'alt': force_escape(escapejs(cms_plugin.get_instance_icon_alt())),
'cancel': True,
}
instance = cms_plugin.get_plugin_instance()[0]
if not instance:
# cancelled before any content was added to plugin
cms_plugin.delete()
context.update({
"deleted":True,
})
return render_to_response('admin/cms/page/plugin_forms_ok.html', context, RequestContext(request))

if not instance:
# instance doesn't exist, call add view
response = plugin_admin.add_view(request)
Expand Down
19 changes: 19 additions & 0 deletions cms/test_utils/testcases.py
Expand Up @@ -26,6 +26,9 @@
URL_CMS_PLUGIN_REMOVE = urljoin(URL_CMS_PAGE_CHANGE, "remove-plugin/")
URL_CMS_TRANSLATION_DELETE = urljoin(URL_CMS_PAGE_CHANGE, "delete-translation/")

URL_CMS_PAGE_HISTORY = urljoin(URL_CMS_PAGE_CHANGE, "history/%d/")
URL_CMS_PLUGIN_HISTORY_EDIT = urljoin(URL_CMS_PAGE_HISTORY, "edit-plugin/")


class _Warning(object):
def __init__(self, message, category, filename, lineno):
Expand Down Expand Up @@ -218,6 +221,22 @@ def get_request(self, path=None, language=None, post_data=None, enforce_csrf_che
request.user = getattr(self, 'user', AnonymousUser())
request.LANGUAGE_CODE = language
request._dont_enforce_csrf_checks = not enforce_csrf_checks

class MockStorage(object):

def __len__(self):
return 0

def __iter__(self):
return iter([])

def add(self, level, message, extra_tags=''):
pass

def update(self, response):
pass

request._messages = MockStorage()
return request

def check_published_page_attributes(self, page):
Expand Down
57 changes: 48 additions & 9 deletions cms/tests/placeholder.py
Expand Up @@ -396,14 +396,8 @@ def test_excercise_get_attached_fields_notplugins(self):
result = [f.name for f in list(ph._get_attached_fields())]
self.assertEqual(result, ['placeholder']) # Simple PH - still one placeholder field name

class PlaceholderAdminTest(CMSTestCase):
placeholderconf = {'test': {
'limits': {
'global': 2,
'TextPlugin': 1,
}
}
}

class PlaceholderAdminTestBase(CMSTestCase):
def get_placeholder(self):
return Placeholder.objects.create(slot='test')

Expand All @@ -414,6 +408,15 @@ def get_admin(self):
def get_post_request(self, data):
return self.get_request(post_data=data)


class PlaceholderAdminTest(PlaceholderAdminTestBase):
placeholderconf = {'test': {
'limits': {
'global': 2,
'TextPlugin': 1,
}
}
}
def test_global_limit(self):
placeholder = self.get_placeholder()
admin = self.get_admin()
Expand Down Expand Up @@ -452,8 +455,44 @@ def test_type_limit(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(response.content, "This placeholder already has the maximum number (1) of TextPlugin plugins.")

def test_edit_plugin_and_cancel(self):
placeholder = self.get_placeholder()
admin = self.get_admin()
data = {
'plugin_type': 'TextPlugin',
'placeholder': placeholder.pk,
'language': 'en',
}
superuser = self.get_superuser()
with UserLoginContext(self, superuser):
with SettingsOverride(CMS_PLACEHOLDER_CONF=self.placeholderconf):
request = self.get_post_request(data)
response = admin.add_plugin(request)
self.assertEqual(response.status_code, 200)
plugin_id = int(response.content)
data = {
'body': 'Hello World',
}
request = self.get_post_request(data)
response = admin.edit_plugin(request, plugin_id)
self.assertEqual(response.status_code, 200)
text_plugin = Text.objects.get(pk=plugin_id)
self.assertEquals('Hello World', text_plugin.body)

# edit again, but this time press cancel
data = {
'body': 'Hello World!!',
'_cancel': True,
}
request = self.get_post_request(data)
response = admin.edit_plugin(request, plugin_id)
self.assertEqual(response.status_code, 200)
text_plugin = Text.objects.get(pk=plugin_id)
self.assertEquals('Hello World', text_plugin.body)



class PlaceholderPluginPermissionTests(PlaceholderAdminTest):
class PlaceholderPluginPermissionTests(PlaceholderAdminTestBase):

def _testuser(self):
u = User(username="test", is_staff = True, is_active = True, is_superuser = False)
Expand Down
30 changes: 28 additions & 2 deletions cms/tests/plugins.py
Expand Up @@ -19,7 +19,7 @@
from cms.test_utils.project.pluginapp.plugins.manytomany_rel.models import (
ArticlePluginModel)
from cms.test_utils.testcases import (CMSTestCase, URL_CMS_PAGE,
URL_CMS_PAGE_ADD, URL_CMS_PLUGIN_ADD, URL_CMS_PLUGIN_EDIT, URL_CMS_PAGE_CHANGE, URL_CMS_PLUGIN_REMOVE)
URL_CMS_PAGE_ADD, URL_CMS_PLUGIN_ADD, URL_CMS_PLUGIN_EDIT, URL_CMS_PAGE_CHANGE, URL_CMS_PLUGIN_REMOVE, URL_CMS_PLUGIN_HISTORY_EDIT)
from cms.sitemaps.cms_sitemap import CMSSitemap
from cms.test_utils.util.context_managers import SettingsOverride
from cms.utils.copy_plugins import copy_plugins_to
Expand Down Expand Up @@ -119,11 +119,37 @@ def test_add_edit_plugin(self):
"body":"Hello World!!",
"_cancel":True,
}
response = self.client.post(URL_CMS_PAGE_ADD, data)
edit_url = '%s%d/' % (URL_CMS_PLUGIN_EDIT, created_plugin_id)
response = self.client.post(edit_url, data)
self.assertEquals(response.status_code, 200)
txt = Text.objects.all()[0]
self.assertEquals("Hello World", txt.body)

def test_plugin_history_view(self):
"""
Test plugin history view
"""
from reversion.models import Version
page_data = self.get_new_page_data()
# two versions created by simply creating the page
response = self.client.post(URL_CMS_PAGE_ADD, page_data)
page = Page.objects.all()[0]
page_id = int(page.pk)
# page version 3
created_plugin_id = self._create_text_plugin_on_page(page)
# page version 4
txt = self._edit_text_plugin(created_plugin_id, "Hello Foo")
self.assertEquals("Hello Foo", txt.body)
# page version 5
txt = self._edit_text_plugin(created_plugin_id, "Hello Bar")
self.assertEquals("Hello Bar", txt.body)
versions = [v.pk for v in Version.objects.get_for_object(page)]
history_url = '%s%d/' % (
URL_CMS_PLUGIN_HISTORY_EDIT % (page_id, versions[-2]),
created_plugin_id)
response = self.client.get(history_url)
self.assertEquals(response.status_code, 200)
self.assertIn('Hello Foo', response.content)

def test_plugin_order(self):
"""
Expand Down

0 comments on commit 7f56291

Please sign in to comment.