Skip to content
Browse files

slqite fixed, mysql fixed (except too many queries)

  • Loading branch information...
1 parent 7b3d65a commit 8f4d4abc692f6bd9892ddc1bbc0c73f323a84a9a @digi604 committed Nov 16, 2012
Showing with 158 additions and 140 deletions.
  1. +5 −3 cms/models/pagemodel.py
  2. +1 −1 cms/models/query.py
  3. +7 −4 cms/test_utils/testcases.py
  4. +2 −0 cms/tests/admin.py
  5. +112 −108 cms/tests/menu.py
  6. +10 −4 cms/tests/page.py
  7. +5 −5 cms/tests/plugins.py
  8. +16 −15 cms/tests/site.py
View
8 cms/models/pagemodel.py
@@ -393,9 +393,10 @@ def publish(self):
# publish, but only if all parents are published!!
published = None
-
if not self.pk:
self.save()
+ if not self.parent_id:
+ self.clear_home_pk_cache()
if self._publisher_can_publish():
########################################################################
# Assign the existing public page in old_public and mark it as
@@ -409,6 +410,7 @@ def publish(self):
self.old_public = old_public
# remove the one-to-one references between public and draft
old_public.publisher_public = None
+ old_public.parent = None #unique constraint
old_public.save()
# we hook into the modified copy_page routing to do the heavy lifting of copying the draft page to a new public page
@@ -429,8 +431,7 @@ def publish(self):
else:
# Nothing left to do
pass
- if not self.parent_id:
- self.clear_home_pk_cache()
+
if self.publisher_public and self.publisher_public.published:
self.publisher_state = Page.PUBLISHER_STATE_DEFAULT
else:
@@ -898,6 +899,7 @@ def get_home_pk_cache(self):
return getattr(self, attr)
def set_home_pk_cache(self, value):
+
attr = "%s_home_pk_cache_%s" % (self.publisher_is_draft and "draft" or "public", self.site_id)
setattr(self, attr, value)
home_pk_cache = property(get_home_pk_cache, set_home_pk_cache)
View
2 cms/models/query.py
@@ -77,7 +77,7 @@ def get_all_pages_with_application(self):
def get_home(self, site=None):
try:
- home = self.published().all_root().order_by("tree_id")[0]
+ home = self.published(site).all_root().order_by("tree_id")[0]
except IndexError:
raise NoHomeFound('No Root page found. Publish at least one page!')
return home
View
11 cms/test_utils/testcases.py
@@ -10,6 +10,7 @@
from django.test import testcases
from django.test.client import RequestFactory
from django.utils.translation import activate
+from django.contrib.sites.models import Site
from menus.menu_pool import menu_pool
from urlparse import urljoin
import sys
@@ -75,20 +76,22 @@ class CMSTestCase(testcases.TestCase):
counter = 1
def _fixture_setup(self):
+ Page.objects.all().delete()
+ User.objects.all().delete()
+ CMSPlugin.objects.all().delete()
+ Site.objects.exclude(pk=1).delete()
super(CMSTestCase, self)._fixture_setup()
self.create_fixtures()
activate("en")
+
def create_fixtures(self):
pass
def _post_teardown(self):
# Needed to clean the menu keys cache, see menu.menu_pool.clear()
menu_pool.clear()
- super(CMSTestCase, self)._post_teardown()
- #Page.objects.all().delete()
- #User.objects.all().delete()
- #CMSPlugin.objects.all().delete()
+ super(CMSTestCase, self)._post_teardown()
set_current_user(None)
def login_user_context(self, user):
View
2 cms/tests/admin.py
@@ -732,6 +732,8 @@ def test_preview_page(self):
site = Site.objects.create(domain='django-cms.org', name='django-cms')
page.site = site
page.save()
+ page.publish()
+ self.assertTrue(page.is_home())
response = self.admin_class.preview_page(request, page.pk)
self.assertEqual(response.status_code, 302)
self.assertEqual(response['Location'],
View
220 cms/tests/menu.py
@@ -5,10 +5,10 @@
from cms.menu import CMSMenu, get_visible_pages
from cms.models import Page
from cms.models.permissionmodels import GlobalPagePermission, PagePermission
-from cms.test_utils.fixtures.menus import (MenusFixture, SubMenusFixture,
+from cms.test_utils.fixtures.menus import (MenusFixture, SubMenusFixture,
SoftrootFixture)
from cms.test_utils.testcases import SettingsOverrideTestCase
-from cms.test_utils.util.context_managers import (SettingsOverride,
+from cms.test_utils.util.context_managers import (SettingsOverride,
LanguageOverride)
from cms.test_utils.util.mock import AttributeObject
from cms.utils.i18n import force_language
@@ -46,7 +46,7 @@ def setUp(self):
menu_pool.menus = {'CMSMenu': self.old_menu['CMSMenu']}
menu_pool.clear(settings.SITE_ID)
activate("en")
-
+
def tearDown(self):
menu_pool.menus = self.old_menu
super(BaseMenuTest, self).tearDown()
@@ -81,19 +81,19 @@ def test_menu_failfast_on_invalid_usage(self):
with SettingsOverride(DEBUG=True, TEMPLATE_DEBUG=True):
tpl = Template("{% load menu_tags %}{% show_menu 0 0 0 0 'menu/menu.html' child %}")
self.assertRaises(TemplateSyntaxError, tpl.render, context)
-
+
def test_basic_cms_menu(self):
self.assertEqual(len(menu_pool.menus), 1)
with force_language("en"):
response = self.client.get(self.get_pages_root()) # path = '/'
self.assertEquals(response.status_code, 200)
request = self.get_request()
-
+
# test the cms menu class
menu = CMSMenu()
nodes = menu.get_nodes(request)
self.assertEqual(len(nodes), len(self.get_all_pages()))
-
+
def test_show_menu(self):
context = self.get_context()
# test standard show_menu
@@ -110,10 +110,14 @@ def test_show_menu(self):
self.assertEqual(nodes[1].get_absolute_url(), self.get_page(4).get_absolute_url())
self.assertEqual(nodes[1].sibling, True)
self.assertEqual(nodes[1].selected, False)
-
+
def test_show_menu_num_queries(self):
context = self.get_context()
# test standard show_menu
+ import logging
+ l = logging.getLogger('django.db.backends')
+ l.setLevel(logging.DEBUG)
+ l.addHandler(logging.StreamHandler())
with self.assertNumQueries(5):
"""
The queries should be:
@@ -152,118 +156,118 @@ def test_only_active_tree(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes[1].children), 0)
self.assertEqual(len(nodes[0].children), 1)
self.assertEqual(len(nodes[0].children[0].children), 1)
context = self.get_context(path=self.get_page(4).get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes[1].children), 1)
self.assertEqual(len(nodes[0].children), 0)
-
+
def test_only_one_active_level(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes[1].children), 0)
self.assertEqual(len(nodes[0].children), 1)
self.assertEqual(len(nodes[0].children[0].children), 0)
-
+
def test_only_level_zero(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_menu 0 0 0 0 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
for node in nodes:
self.assertEqual(len(node.children), 0)
-
-
+
+
def test_only_level_one(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_menu 1 1 100 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), len(self.get_level(1)))
for node in nodes:
self.assertEqual(len(node.children), 0)
-
-
+
+
def test_only_level_one_active(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_menu 1 1 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].descendant, True)
self.assertEqual(len(nodes[0].children), 0)
-
+
def test_level_zero_and_one(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_menu 0 1 100 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 2)
for node in nodes:
self.assertEqual(len(node.children), 1)
-
+
def test_show_submenu(self):
context = self.get_context()
# test standard show_menu
tpl = Template("{% load menu_tags %}{% show_sub_menu %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(nodes[0].descendant, True)
self.assertEqual(len(nodes), 1)
self.assertEqual(len(nodes[0].children), 1)
-
+
tpl = Template("{% load menu_tags %}{% show_sub_menu 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
self.assertEqual(len(nodes[0].children), 0)
-
+
def test_show_breadcrumb(self):
context = self.get_context(path=self.get_page(3).get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 3)
tpl = Template("{% load menu_tags %}{% show_breadcrumb 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 2)
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 1)
tpl = Template("{% load menu_tags %}{% show_breadcrumb 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 0)
-
+
page1 = self.get_page(1)
page1.in_navigation = False
page1.save()
page2 = self.get_page(2)
context = self.get_context(path=page2.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 2)
self.assertEqual(nodes[0].get_absolute_url(), self.get_pages_root())
self.assertEqual(isinstance(nodes[0], NavigationNode), True)
self.assertEqual(nodes[1].get_absolute_url(), page2.get_absolute_url())
-
+
def test_language_chooser(self):
# test simple language chooser with default args
lang_settings = copy.deepcopy(settings.CMS_LANGUAGES)
@@ -289,7 +293,7 @@ def test_page_language_url(self):
tpl = Template("{%% load menu_tags %%}{%% page_language_url '%s' %%}" % settings.LANGUAGES[0][0])
url = tpl.render(context)
self.assertEqual(url, "%s" % path)
-
+
def test_show_menu_below_id(self):
page2 = self.get_page(2)
page2.reverse_id = "hello"
@@ -299,7 +303,7 @@ def test_show_menu_below_id(self):
page5 = self.get_page(5)
context = self.get_context(path=page5.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'hello' %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
page3_url = self.get_page(3).get_absolute_url()
@@ -308,22 +312,22 @@ def test_show_menu_below_id(self):
page2.save()
context = self.get_context(path=page5.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu_below_id 'hello' %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].get_absolute_url(), page3_url)
-
+
def test_unpublished(self):
page2 = self.get_page(2)
page2.published = False
page2.save()
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_menu %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 2)
self.assertEqual(len(nodes[0].children), 0)
-
+
def test_home_not_in_menu(self):
page1 = self.get_page(1)
page1.in_navigation = False
@@ -333,7 +337,7 @@ def test_home_not_in_menu(self):
page4.save()
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].get_absolute_url(), self.get_page(2).get_absolute_url())
@@ -344,10 +348,10 @@ def test_home_not_in_menu(self):
menu_pool.clear(settings.SITE_ID)
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 2)
-
+
def test_show_submenu_from_non_menu_page(self):
"""
Here's the structure bit we're interested in:
@@ -362,40 +366,40 @@ def test_show_submenu_from_non_menu_page(self):
page6 = self.get_page(6)
context = self.get_context(page6.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
number_of_p6_children = len(page6.children.filter(in_navigation=True))
self.assertEqual(len(nodes), number_of_p6_children)
-
+
page7 = self.get_page(7)
context = self.get_context(page7.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 1 100 0 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), number_of_p6_children)
-
+
tpl = Template("{% load menu_tags %}{% show_menu 2 100 0 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
number_of_p7_children = len(page7.children.filter(in_navigation=True))
self.assertEqual(len(nodes), number_of_p7_children)
-
+
def test_show_breadcrumb_invisible(self):
# Must use the drafts to find the parent when calling create_page
parent = Page.objects.drafts().get(title_set__title='P3')
invisible_page = create_page("invisible", "nav_playground.html", "en",
parent=parent, published=True, in_navigation=False)
context = self.get_context(path=invisible_page.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_breadcrumb %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 3)
tpl = Template("{% load menu_tags %}{% show_breadcrumb 0 'menu/breadcrumb.html' 1 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 3)
tpl = Template("{% load menu_tags %}{% show_breadcrumb 0 'menu/breadcrumb.html' 0 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['ancestors']
self.assertEqual(len(nodes), 4)
@@ -416,20 +420,20 @@ def test_build_nodes_inner_for_worst_case_menu(self):
node3 = NavigationNode('Test3', '/test3/', 3, 4)
node4 = NavigationNode('Test4', '/test4/', 4, 5)
node5 = NavigationNode('Test5', '/test5/', 5, None)
-
+
menu_class_name = 'Test'
- nodes = [node1,node2,node3,node4,node5,]
+ nodes = [node1, node2, node3, node4, node5, ]
len_nodes = len(nodes)
-
+
final_list = _build_nodes_inner_for_one_menu(nodes, menu_class_name)
self.assertEqual(len(final_list), len_nodes)
-
+
self.assertEqual(node1.parent, node2)
self.assertEqual(node2.parent, node3)
self.assertEqual(node3.parent, node4)
self.assertEqual(node4.parent, node5)
self.assertEqual(node5.parent, None)
-
+
self.assertEqual(node1.children, [])
self.assertEqual(node2.children, [node1])
self.assertEqual(node3.children, [node2])
@@ -444,7 +448,7 @@ def test_build_nodes_inner_for_circular_menu(self):
Go nuts implementing it :)
'''
pass
-
+
def test_build_nodes_inner_for_broken_menu(self):
'''
Tests a broken menu tree (non-existing parent)
@@ -462,21 +466,21 @@ def test_build_nodes_inner_for_broken_menu(self):
node3 = NavigationNode('Test3', '/test3/', 3, 4)
node4 = NavigationNode('Test4', '/test4/', 4, 5)
node5 = NavigationNode('Test5', '/test5/', 5, None)
-
+
menu_class_name = 'Test'
- nodes = [node1,node2,node3,node4,node5,]
-
+ nodes = [node1, node2, node3, node4, node5, ]
+
final_list = _build_nodes_inner_for_one_menu(nodes, menu_class_name)
- self.assertEqual(len(final_list), 3)
+ self.assertEqual(len(final_list), 3)
self.assertFalse(node1 in final_list)
self.assertFalse(node2 in final_list)
-
+
self.assertEqual(node1.parent, None)
self.assertEqual(node2.parent, None)
self.assertEqual(node3.parent, node4)
self.assertEqual(node4.parent, node5)
self.assertEqual(node5.parent, None)
-
+
self.assertEqual(node1.children, [])
self.assertEqual(node2.children, [])
self.assertEqual(node3.children, [])
@@ -488,23 +492,23 @@ def test_utils_mark_descendants(self):
mark_descendants(tree_nodes)
for node in flat_nodes:
self.assertTrue(node.descendant, node)
-
+
def test_utils_find_selected(self):
tree_nodes, flat_nodes = self._get_nodes()
node = flat_nodes[0]
selected = find_selected(tree_nodes)
self.assertEqual(selected, node)
selected = find_selected([])
self.assertEqual(selected, None)
-
+
def test_utils_cut_levels(self):
tree_nodes, flat_nodes = self._get_nodes()
self.assertEqual(cut_levels(tree_nodes, 1), [flat_nodes[1]])
-
+
def test_empty_menu(self):
context = self.get_context()
tpl = Template("{% load menu_tags %}{% show_menu 0 100 100 100 %}")
- tpl.render(context)
+ tpl.render(context)
nodes = context['children']
self.assertEqual(len(nodes), 0)
@@ -537,13 +541,13 @@ class AdvancedSoftrootTests(SoftrootFixture, SettingsOverrideTestCase):
settings_overrides = {
'CMS_PERMISSION': False
}
-
+
def tearDown(self):
Page.objects.all().delete()
-
+
def get_page(self, name):
return Page.objects.public().get(title_set__slug=name)
-
+
def assertTreeQuality(self, a, b, *attrs):
"""
Checks that the node-lists a and b are the same for attrs.
@@ -552,14 +556,14 @@ def assertTreeQuality(self, a, b, *attrs):
"""
msg = '%r != %r with %r, %r' % (len(a), len(b), a, b)
self.assertEqual(len(a), len(b), msg)
- for n1, n2 in zip(a,b):
+ for n1, n2 in zip(a, b):
for attr in attrs:
a1 = getattr(n1, attr)
a2 = getattr(n2, attr)
msg = '%r != %r with %r, %r (%s)' % (a1, a2, n1, n2, attr)
self.assertEqual(a1, a2, msg)
self.assertTreeQuality(n1.children, n2.children)
-
+
def test_top_not_in_nav(self):
"""
top: not in navigation
@@ -579,7 +583,7 @@ def test_top_not_in_nav(self):
# root is NOT a soft root
context = self.get_context(aaa.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
hard_root = context['children']
# root IS a soft root
root = self.get_page('root')
@@ -588,11 +592,11 @@ def test_top_not_in_nav(self):
aaa = self.get_page('aaa')
context = self.get_context(aaa.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
soft_root = context['children']
# assert the two trees are equal in terms of 'level' and 'title'
self.assertTreeQuality(hard_root, soft_root, 'level', 'title')
-
+
def test_top_in_nav(self):
"""
top: in navigation
@@ -625,7 +629,7 @@ def test_top_in_nav(self):
# root is NOT a soft root
context = self.get_context(aaa.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
hard_root = context['children']
mock_tree = [
AttributeObject(title='top', level=0, children=[
@@ -650,7 +654,7 @@ def test_top_in_nav(self):
aaa = self.get_page('aaa')
context = self.get_context(aaa.get_absolute_url())
tpl = Template("{% load menu_tags %}{% show_menu 0 100 0 100 %}")
- tpl.render(context)
+ tpl.render(context)
soft_root = context['children']
mock_tree = [
AttributeObject(title='root', level=0, children=[
@@ -691,7 +695,7 @@ def test_show_submenu(self):
nodes = context['children']
self.assertEqual(len(nodes), 1)
self.assertEqual(nodes[0].id, subpage.pk)
-
+
def test_show_submenu_num_queries(self):
page = self.get_page(6)
context = self.get_context(page.get_absolute_url())
@@ -739,7 +743,7 @@ def test_not_in_navigation(self):
self.assertEqual(len(children), 1, repr(children))
child = children[0]
self.assertEqual(child.id, c.publisher_public.id)
-
+
def test_not_in_navigation_num_queries(self):
"""
Test for issue 521
@@ -753,7 +757,7 @@ def test_not_in_navigation_num_queries(self):
"""
a = create_page('A', 'nav_playground.html', 'en', published=True,
in_navigation=True, reverse_id='a')
- b =create_page('B', 'nav_playground.html', 'en', parent=a,
+ b = create_page('B', 'nav_playground.html', 'en', parent=a,
published=True, in_navigation=True)
create_page('C', 'nav_playground.html', 'en', parent=b,
published=True, in_navigation=True)
@@ -780,15 +784,15 @@ class ViewPermissionMenuTests(SettingsOverrideTestCase):
'CMS_PERMISSION': True,
'CMS_PUBLIC_FOR': 'all',
}
-
+
def get_request(self, user=None):
attrs = {
'user': user or AnonymousUser(),
'REQUEST': {},
'session': {},
}
return type('Request', (object,), attrs)
-
+
def test_public_for_all_staff(self):
request = self.get_request()
request.user.is_staff = True
@@ -799,7 +803,7 @@ def test_public_for_all_staff(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [1])
-
+
def test_public_for_all_staff_assert_num_queries(self):
request = self.get_request()
request.user.is_staff = True
@@ -812,9 +816,9 @@ def test_public_for_all_staff_assert_num_queries(self):
"""
The queries are:
PagePermission count query
- """
+ """
get_visible_pages(request, pages)
-
+
def test_public_for_all(self):
user = User.objects.create_user('user', 'user@domain.com', 'user')
request = self.get_request(user)
@@ -825,7 +829,7 @@ def test_public_for_all(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [1])
-
+
def test_public_for_all_num_queries(self):
user = User.objects.create_user('user', 'user@domain.com', 'user')
request = self.get_request(user)
@@ -843,7 +847,7 @@ def test_public_for_all_num_queries(self):
GlobalpagePermission query for user
"""
get_visible_pages(request, pages, site)
-
+
def test_unauthed(self):
request = self.get_request()
page = Page()
@@ -853,7 +857,7 @@ def test_unauthed(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [1])
-
+
def test_unauthed_num_queries(self):
request = self.get_request()
site = Site()
@@ -871,11 +875,11 @@ def test_unauthed_num_queries(self):
global is not executed because it's lazy
"""
get_visible_pages(request, pages, site)
-
+
def test_authed_basic_perm(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User()
- user.username="test"
+ user.username = "test"
user.is_staff = True
user.save()
user.user_permissions.add(Permission.objects.get(codename='view_page'))
@@ -887,13 +891,13 @@ def test_authed_basic_perm(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [1])
-
+
def test_authed_basic_perm_num_queries(self):
site = Site()
site.pk = 1
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User()
- user.username="test"
+ user.username = "test"
user.is_staff = True
user.save()
user.user_permissions.add(Permission.objects.get(codename='view_page'))
@@ -910,7 +914,7 @@ def test_authed_basic_perm_num_queries(self):
GlobalpagePermission count query
"""
get_visible_pages(request, pages, site)
-
+
def test_authed_no_access(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User.objects.create_user('user', 'user@domain.com', 'user')
@@ -922,7 +926,7 @@ def test_authed_no_access(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [])
-
+
def test_authed_no_access_num_queries(self):
site = Site()
site.pk = 1
@@ -941,7 +945,7 @@ def test_authed_no_access_num_queries(self):
globalpagepermissino calculation
"""
get_visible_pages(request, pages, site)
-
+
def test_unauthed_no_access(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
request = self.get_request()
@@ -952,7 +956,7 @@ def test_unauthed_no_access(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [])
-
+
def test_unauthed_no_access_num_queries(self):
site = Site()
site.pk = 1
@@ -964,7 +968,7 @@ def test_unauthed_no_access_num_queries(self):
pages = [page]
with self.assertNumQueries(1):
get_visible_pages(request, pages, site)
-
+
def test_page_permissions(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User.objects.create_user('user', 'user@domain.com', 'user')
@@ -973,8 +977,8 @@ def test_page_permissions(self):
PagePermission.objects.create(can_view=True, user=user, page=page)
pages = [page]
result = get_visible_pages(request, pages)
- self.assertEqual(result, [1])
-
+ self.assertEqual(result, [page.pk])
+
def test_page_permissions_num_queries(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User.objects.create_user('user', 'user@domain.com', 'user')
@@ -989,7 +993,7 @@ def test_page_permissions_num_queries(self):
GlobalpagePermission query for user
"""
get_visible_pages(request, pages)
-
+
def test_page_permissions_view_groups(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User.objects.create_user('user', 'user@domain.com', 'user')
@@ -1000,8 +1004,8 @@ def test_page_permissions_view_groups(self):
PagePermission.objects.create(can_view=True, group=group, page=page)
pages = [page]
result = get_visible_pages(request, pages)
- self.assertEqual(result, [1])
-
+ self.assertEqual(result, [page.pk])
+
def test_page_permissions_view_groups_num_queries(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User.objects.create_user('user', 'user@domain.com', 'user')
@@ -1019,7 +1023,7 @@ def test_page_permissions_view_groups_num_queries(self):
Group query via PagePermission
"""
get_visible_pages(request, pages)
-
+
def test_global_permission(self):
with SettingsOverride(CMS_PUBLIC_FOR='staff'):
user = User.objects.create_user('user', 'user@domain.com', 'user')
@@ -1032,7 +1036,7 @@ def test_global_permission(self):
pages = [page]
result = get_visible_pages(request, pages)
self.assertEqual(result, [1])
-
+
def test_global_permission_num_queries(self):
site = Site()
site.pk = 1
@@ -1125,7 +1129,7 @@ class SoftrootTests(SettingsOverrideTestCase):
'CMS_SOFTROOT': True,
'CMS_PERMISSION': False
}
-
+
def test_basic_home(self):
"""
Given the tree:
@@ -1175,7 +1179,7 @@ def test_basic_home(self):
self.assertEqual(len(cmsnode.children), 0)
self.assertEqual(len(shopnode.children), 0)
self.assertEqual(len(peoplenode.children), 0)
-
+
def test_basic_projects(self):
"""
Given the tree:
@@ -1218,7 +1222,7 @@ def test_basic_projects(self):
self.assertEqual(shopnode.id, djangoshop.publisher_public.pk)
self.assertEqual(len(cmsnode.children), 0)
self.assertEqual(len(shopnode.children), 0)
-
+
def test_basic_djangocms(self):
"""
Given the tree:
@@ -1261,7 +1265,7 @@ def test_basic_djangocms(self):
self.assertEqual(shopnode.id, djangoshop.publisher_public.pk)
self.assertEqual(len(cmsnode.children), 0)
self.assertEqual(len(shopnode.children), 0)
-
+
def test_basic_people(self):
"""
Given the tree:
View
14 cms/tests/page.py
@@ -169,19 +169,22 @@ def test_details_view(self):
Test the details view
"""
superuser = self.get_superuser()
+ self.assertEqual(Page.objects.all().count(), 0)
with self.login_user_context(superuser):
response = self.client.get(self.get_pages_root())
self.assertEqual(response.status_code, 404)
page = create_page('test page 1', "nav_playground.html", "en")
page.publish()
response = self.client.get(self.get_pages_root())
- self.assertEqual(response.status_code, 404)
+ self.assertEqual(response.status_code, 200)
self.assertTrue(page.publish())
- create_page("test page 2", "nav_playground.html", "en",
+ page2 = create_page("test page 2", "nav_playground.html", "en",
parent=page, published=True)
homepage = Page.objects.get_home()
self.assertTrue(homepage.get_slug(), 'test-page-1')
- response = self.client.get(self.get_pages_root())
+
+ self.assertEqual(page2.get_absolute_url(), '/en/test-page-2/')
+ response = self.client.get(page2.get_absolute_url())
self.assertEqual(response.status_code, 200)
def test_edit_page(self):
@@ -420,11 +423,13 @@ def test_edit_page_other_site_and_language(self):
different from the site you are editing and the language isn't available
for the current site.
"""
- site = Site.objects.create(domain='otherlang', name='otherlang')
+ self.assertEqual(Site.objects.all().count(), 1)
+ site = Site.objects.create(domain='otherlang', name='otherlang', pk=2)
# Change site for this session
page_data = self.get_new_page_data()
page_data['site'] = site.pk
page_data['title'] = 'changed title'
+ self.assertEqual(site.pk, 2)
TESTLANG = settings.CMS_LANGUAGES[site.pk][0]['code']
page_data['language'] = TESTLANG
superuser = self.get_superuser()
@@ -541,6 +546,7 @@ def test_get_page_without_final_slash(self):
page = create_page("page", "nav_playground.html", "en", slug="page",
published=True, parent=root)
root.publish()
+ time.sleep(1)
page.publish()
request = self.get_request('/en/page')
found_page = get_page_from_request(request)
View
10 cms/tests/plugins.py
@@ -607,7 +607,7 @@ def test_copy_textplugin(self):
plugin.body = plugin_tags_to_admin_html(' {{ plugin_object %s }} {{ plugin_object %s }} ' % (str(plugin_ref_1.pk), str(plugin_ref_2.pk)))
plugin.save()
- self.assertEquals(plugin.pk, 1)
+
page_data = self.get_new_page_data()
#create 2nd language page
@@ -635,10 +635,10 @@ def test_copy_textplugin(self):
self.assertEquals(CMSPlugin.objects.filter(language=self.FIRST_LANG).count(), 3)
self.assertEquals(CMSPlugin.objects.filter(language=self.SECOND_LANG).count(), 3)
self.assertEquals(CMSPlugin.objects.count(), 6)
-
- new_plugin = Text.objects.get(pk=6)
+ plugins = list(Text.objects.all())
+ new_plugin = plugins[-1]
idlist = sorted(plugin_tags_to_id_list(new_plugin.body))
- expected = sorted([4, 5])
+ expected = sorted([plugins[3].pk, plugins[4].pk])
self.assertEquals(idlist, expected)
def test_empty_plugin_is_ignored(self):
@@ -669,7 +669,7 @@ def test_editing_plugin_changes_page_modification_time_in_sitemap(self):
plugin = self._edit_text_plugin(plugin_id, "fnord")
actual_last_modification_time = CMSSitemap().lastmod(page)
- self.assertEqual(plugin.changed_date, actual_last_modification_time)
+ self.assertEqual(plugin.changed_date - datetime.timedelta(microseconds=plugin.changed_date.microsecond), actual_last_modification_time - datetime.timedelta(microseconds=actual_last_modification_time.microsecond))
class FileSystemPluginTests(PluginsTestBaseCase):
View
31 cms/tests/site.py
@@ -13,43 +13,44 @@ class SiteTestCase(CMSTestCase):
All stuff which is changing settings.SITE_ID for tests should come here.
"""
def setUp(self):
+ self.assertEqual(Site.objects.all().count(), 1)
with SettingsOverride(SITE_ID=1):
-
- u = User(username="test", is_staff = True, is_active = True, is_superuser = True)
+
+ u = User(username="test", is_staff=True, is_active=True, is_superuser=True)
u.set_password("test")
u.save()
-
+
# setup sites
- self.site2 = Site.objects.create(domain="sample2.com", name="sample2.com")
- self.site3 = Site.objects.create(domain="sample3.com", name="sample3.com")
-
+ self.site2 = Site.objects.create(domain="sample2.com", name="sample2.com", pk=2)
+ self.site3 = Site.objects.create(domain="sample3.com", name="sample3.com", pk=3)
+
self._login_context = self.login_user_context(u)
self._login_context.__enter__()
-
+
def tearDown(self):
self._login_context.__exit__(None, None, None)
-
-
+
+
def test_site_framework(self):
#Test the site framework, and test if it's possible to disable it
with SettingsOverride(SITE_ID=self.site2.pk):
create_page("page_2a", "nav_playground.html", "de", site=self.site2)
-
+
response = self.client.get("/en/admin/cms/page/?site__exact=%s" % self.site3.pk)
self.assertEqual(response.status_code, 200)
create_page("page_3b", "nav_playground.html", "de", site=self.site3)
-
+
with SettingsOverride(SITE_ID=self.site3.pk):
create_page("page_3a", "nav_playground.html", "nl", site=self.site3)
-
+
# with param
self.assertEqual(Page.objects.on_site(self.site2.pk).count(), 1)
self.assertEqual(Page.objects.on_site(self.site3.pk).count(), 2)
-
+
self.assertEqual(Page.objects.drafts().on_site().count(), 2)
-
+
with SettingsOverride(SITE_ID=self.site2.pk):
# without param
self.assertEqual(Page.objects.drafts().on_site().count(), 1)
-
+

0 comments on commit 8f4d4ab

Please sign in to comment.
Something went wrong with that request. Please try again.