Permalink
Browse files

Merge pull request #927 from ojii/url-overwrite-bug

Url overwrite bug
  • Loading branch information...
2 parents 087bc70 + 88ff422 commit 0e6cc4b81beff2234fa49a0caa3243b36cf6fba4 @ojii ojii committed Aug 4, 2011
Showing with 44 additions and 11 deletions.
  1. +2 −1 cms/admin/forms.py
  2. +42 −10 cms/tests/admin.py
View
@@ -176,7 +176,8 @@ def clean_overwrite_url(self):
if url:
if not any_path_re.match(url):
raise forms.ValidationError(_('Invalid URL, use /my/url format.'))
- if get_page_from_path(url.strip('/')):
+ page = get_page_from_path(url.strip('/'))
+ if page and page.pk != self.instance.pk:
raise forms.ValidationError(_('Page with redirect url %r already exist') % url)
return url
View
@@ -1,10 +1,12 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
-from cms.admin.dialog.forms import ModeratorForm, PermissionForm, \
- PermissionAndModeratorForm
-from cms.admin.dialog.views import _form_class_selector
-from cms.admin.pageadmin import contribute_fieldsets, contribute_list_filter, PageAdmin
from cms.admin.change_list import CMSChangeList
+from cms.admin.dialog.forms import (ModeratorForm, PermissionForm,
+ PermissionAndModeratorForm)
+from cms.admin.dialog.views import _form_class_selector
+from cms.admin.forms import PageForm
+from cms.admin.pageadmin import (contribute_fieldsets, contribute_list_filter,
+ PageAdmin)
from cms.api import create_page, create_title, add_plugin
from cms.apphook_pool import apphook_pool, ApphookPool
from cms.models.moderatormodels import PageModeratorState
@@ -14,26 +16,26 @@
from cms.models.titlemodels import Title
from cms.plugins.text.models import Text
from cms.test_utils import testcases as base
-from cms.test_utils.util.request_factory import RequestFactory
from cms.test_utils.testcases import (CMSTestCase, URL_CMS_PAGE_DELETE,
URL_CMS_PAGE, URL_CMS_TRANSLATION_DELETE)
-
from cms.test_utils.util.context_managers import SettingsOverride
from cms.test_utils.util.mock import AttributeObject
+from cms.test_utils.util.request_factory import RequestFactory
from django.conf import settings
from django.contrib import admin
from django.contrib.admin.sites import site
-from django.contrib.auth.models import User, Permission
+from django.contrib.auth.models import User, Permission, AnonymousUser
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied
from django.core.urlresolvers import reverse
-from django.http import Http404, HttpResponseBadRequest, HttpResponseForbidden, \
- HttpResponse
+from django.http import (Http404, HttpResponseBadRequest, HttpResponseForbidden,
+ HttpResponse)
from django.test.client import Client
from menus.menu_pool import menu_pool
from types import MethodType
from unittest import TestCase
+
class AdminTestsBase(CMSTestCase):
def setUp(self):
@@ -406,6 +408,7 @@ def func_true(self):
return True
def func_false(self):
return False
+ old_get_apphooks = apphook_pool.get_apphooks
apphook_pool.get_apphooks = MethodType(func_true, apphook_pool, ApphookPool)
control = AttributeObject()
contribute_fieldsets(control)
@@ -415,6 +418,7 @@ def func_false(self):
self.validate_attributes(control, experiment, ['fieldsets', 'advanced_fields'])
self.assertTrue('application_urls' in control.advanced_fields, control.advanced_fields)
self.assertFalse('application_urls' in experiment.advanced_fields, control.advanced_fields)
+ apphook_pool.get_apphooks = old_get_apphooks
class AdminListFilterTests(TestCase):
@@ -849,4 +853,32 @@ def test_plugins_copy_requires_permissions(self):
# After he got the permissions, he can edit the plugin
self._give_permission(normal_guy, Text, 'add')
response = client.post(url, data)
- self.assertEqual(response.status_code, HttpResponse.status_code)
+ self.assertEqual(response.status_code, HttpResponse.status_code)
+
+
+class AdminFormsTests(TestCase):
+ def test_clean_overwrite_url(self):
+ user = AnonymousUser()
+ user.is_superuser = True
+ user.pk = 1
+ request = type('Request', (object,), {'user': user})
+ with SettingsOverride(CMS_MODERATOR=False):
+ data = {
+ 'title': 'TestPage',
+ 'slug': 'test-page',
+ 'language': 'en',
+ 'overwrite_url': '/overwrite/url/',
+ 'site': Site.objects.get_current().pk,
+ 'template': settings.CMS_TEMPLATES[0][0],
+ 'published': True
+ }
+
+ form = PageForm(data)
+ self.assertTrue(form.is_valid(), form.errors.as_text())
+ # WTF? WHY DOES form.save() not handle this stuff???
+ instance = form.save()
+ instance.permission_user_cache = user
+ instance.permission_advanced_settings_cache = True
+ Title.objects.set_or_create(request, instance, form, 'en')
+ form = PageForm(data, instance=instance)
+ self.assertTrue(form.is_valid(), form.errors.as_text())

0 comments on commit 0e6cc4b

Please sign in to comment.