Permalink
Browse files

some progress in digging into 662

  • Loading branch information...
Jonas Obrist
Jonas Obrist committed Jan 23, 2011
1 parent e291db6 commit e0a822e2e6e824eb872e12770090e369164454f9
Showing with 576 additions and 502 deletions.
  1. +9 −9 cms/menu.py
  2. +2 −2 cms/test/js_testcases.py
  3. +30 −3 cms/test/testcases.py
  4. +14 −0 cms/test/util/mock.py
  5. +1 −1 cms/tests/__init__.py
  6. +519 −487 cms/tests/menu.py
  7. +1 −0 tests/testapp/fixtures/menus.json
View
@@ -175,14 +175,14 @@ def modify(self, request, nodes, namespace, root_id, post_cut, breadcrumb):
selected.parent = None
nodes = [selected] + nodes
else:
- nodes = self.find_ancestors(selected, nodes)
- nodes = self.find_children(selected, nodes)
+ nodes = self.find_ancestors_and_remove_children(selected, nodes)
+ nodes = self.find_and_remove_children(selected, nodes)
else:
for node in root_nodes:
- self.find_children(node, nodes)
+ self.find_and_remove_children(node, nodes)
return nodes
- def find_children(self, node, nodes):
+ def find_and_remove_children(self, node, nodes):
for n in node.children:
if n.attr.get("soft_root", False):
self.remove_children(n, nodes)
@@ -194,7 +194,7 @@ def remove_children(self, node, nodes):
self.remove_children(n, nodes)
node.children = []
- def find_ancestors(self, node, nodes):
+ def find_ancestors_and_remove_children(self, node, nodes):
is_root = False
if node.parent:
if node.parent.attr.get("soft_root", False):
@@ -203,16 +203,16 @@ def find_ancestors(self, node, nodes):
node.parent.parent = None
nodes = [node.parent] + nodes
else:
- nodes = self.find_ancestors(node.parent, nodes)
+ nodes = self.find_ancestors_and_remove_children(node.parent, nodes)
else:
for n in nodes:
if n != node and not n.parent:
- self.find_children(n, nodes)
+ self.find_and_remove_children(n, nodes)
for n in node.children:
if n != node:
- self.find_children(n, nodes)
+ self.find_and_remove_children(n, nodes)
if is_root:
n.parent = None
return nodes
-menu_pool.register_modifier(SoftRootCutter)
+menu_pool.register_modifier(SoftRootCutter)
View
@@ -1,13 +1,13 @@
# -*- coding: utf-8 -*-
from __future__ import with_statement
+from django.test.testcases import TestCase
from spidermonkey import Runtime
import os
-import unittest
THISDIR = os.path.abspath(os.path.dirname(__file__))
MEDIADIR = os.path.join(THISDIR, '../media/cms/')
-class BaseJavascriptTestCase(unittest.TestCase):
+class BaseJavascriptTestCase(TestCase):
def _get_runtime(self):
return Runtime()
View
@@ -5,7 +5,7 @@
from cms.models.permissionmodels import PagePermission, PageUser
from cms.models.pluginmodel import CMSPlugin
from cms.plugins.text.models import Text
-from cms.test.util.context_managers import UserLoginContext
+from cms.test.util.context_managers import UserLoginContext, SettingsOverride
from cms.utils.permissions import _thread_locals
from django.conf import settings
from django.contrib.auth.models import User, AnonymousUser
@@ -108,10 +108,18 @@ def get_new_page_data(self, parent_id=''):
def print_page_structure(self, title=None):
"""Just a helper to see the page struct.
"""
- print "-------------------------- %s --------------------------------" % (title or "page structure")
- for page in Page.objects.drafts().order_by('tree_id', 'parent', 'lft'):
+ for page in Page.objects.drafts().order_by('tree_id', 'lft'):
print "%s%s #%d" % (" " * (page.level), page, page.id)
+ def print_node_structure(self, nodes, *extra):
+ def _rec(nodes, level=0):
+ ident = level * ' '
+ for node in nodes:
+ raw_attrs = [(bit, getattr(node, bit, "unknown")) for bit in extra]
+ attrs = ', '.join(['%r: %r' % data for data in raw_attrs])
+ print "%s%s: %s" % (ident, node.title, attrs)
+ _rec(node.children, level+1)
+ _rec(nodes)
def assertObjectExist(self, qs, **filter):
try:
@@ -448,3 +456,22 @@ def failUnlessWarns(self, category, message, f, *args, **kwargs):
return result
assertWarns = failUnlessWarns
+
+
+class SettingsOverrideTestCase(CMSTestCase):
+ settings_overrides = {}
+
+ def _pre_setup(self):
+ self._enter_settings_override()
+ super(SettingsOverrideTestCase, self)._pre_setup()
+
+ def _enter_settings_override(self):
+ self._settings_ctx_manager = SettingsOverride(**self.settings_overrides)
+ self._settings_ctx_manager.__enter__()
+
+ def _post_teardown(self):
+ super(SettingsOverrideTestCase, self)._post_teardown()
+ self._exit_settings_override()
+
+ def _exit_settings_override(self):
+ self._settings_ctx_manager.__exit__(None, None, None)
View
@@ -0,0 +1,14 @@
+class AttributeObject(object):
+ """
+ mock = AttributeObject(hello='world')
+ mock.hello # 'world'
+ """
+ def __init__(self, **kwargs):
+ for key, value in kwargs.items():
+ setattr(self, key, value)
+
+
+class DefaultAttributeObject(AttributeObject):
+ def __init__(self, default, **kwargs):
+ self.__default = default
+ super(DefaultAttributeObject, self).__init__(**kwargs)
View
@@ -2,7 +2,7 @@
from cms.tests.admin import AdminTestCase
from cms.tests.apphooks import ApphooksTestCase
from cms.tests.docs import DocsTestCase
-from cms.tests.menu import MenusTestCase
+from cms.tests.menu import FixturesMenuTests, MenuTests, AdvancedSoftrootTests
from cms.tests.navextender import NavExtenderTestCase
from cms.tests.nonroot import NonRootCase
from cms.tests.page import PagesTestCase, NoAdminPageTests
Oops, something went wrong.

0 comments on commit e0a822e

Please sign in to comment.