Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fixed import which caused error in cookie unquoting #1292

Closed
wants to merge 6 commits into
from
View
@@ -24,7 +24,8 @@
from django.conf import settings
from django.contrib import admin
from django.contrib.admin.options import IncorrectLookupParameters
-from django.contrib.admin.util import unquote, get_deleted_objects
+from django.contrib.admin.util import get_deleted_objects
+from urllib2 import unquote
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied, ObjectDoesNotExist
from django.core.urlresolvers import reverse
View
@@ -370,6 +370,53 @@ def test_changelist_items(self):
self.assertEqual(root_page.get_children()[1], second_level_page_bottom)
self.assertEqual(root_page.get_children()[0].get_children()[0], third_level_page)
+ def test_changelist_tree(self):
+ """ This test checks for proper jstree cookie unquoting.
+
+ It should be converted to a selenium test to actually test the jstree behaviour.
+ Cookie set below is just a forged example (from live session)
+ """
+ admin = self._get_guys(True)
+ first_level_page = create_page('level1', 'nav_playground.html', 'en')
+ second_level_page_top = create_page('level21', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= first_level_page)
+ second_level_page_bottom = create_page('level22', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= self.reload(first_level_page))
+ third_level_page = create_page('level3', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= second_level_page_top)
+
+ url = reverse('admin:cms_%s_changelist' % Page._meta.module_name)
+ client = Client()
+ client.login(username='admin', password='admin')
+ client.cookies['djangocms_nodes_open'] = 'page_1%2Cpage_2'
+ response = client.get(url)
+ self.assertContains(response,"<title>List of pages</title>")
@andrewschoen

andrewschoen Jun 15, 2012

Contributor

Let's test the context variable open_menu_trees here. If it contains the id's for the two pages we put in the cookie then we know the unquoting worked.

Something like this.

self.assertEquals(response.context["open_menu_trees"], [1,2])

@yakky

yakky Jun 16, 2012

Contributor

Cool.
Thanks. I added a new test (see below) with a different testing strategy with the assert you suggested.
I overlooked the context var

+
+ def test_changelist_unquote(self):
+ """ This test checks for proper jstree cookie unquoting.
+
+ It should be converted to a selenium test to actually test the jstree behaviour.
+ Cookie set below is just a forged example (from live session)
+ """
+ from cms.admin.pageadmin import PageAdmin
+ first_level_page = create_page('level1', 'nav_playground.html', 'en')
+ second_level_page_top = create_page('level21', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= first_level_page)
+ second_level_page_bottom = create_page('level22', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= self.reload(first_level_page))
+ third_level_page = create_page('level3', "nav_playground.html", "en",
+ created_by=admin, published=True, parent= second_level_page_top)
+
+ url = reverse('admin:cms_%s_changelist' % Page._meta.module_name)
+ request = self.request_factory.get(url)
+ request.user = self.get_superuser()
+ request.session = {}
+ request.COOKIES = {'djangocms_nodes_open':'page_1%2Cpage_2'}
+ pageadmin = site._registry[Page]
+ response = pageadmin.changelist_view(request)
+ self.assertEqual(response.status_code, 200)
+ self.assertTemplateUsed("admin/cms/page/change_list.html")
+ self.assertEquals(response.context["open_menu_trees"], [1,2])
class AdminFieldsetTests(TestCase):