[Zope-CVS] CVS: Products/CompositePage/tests - __init__.py:1.1 test_tool.py:1.1

Shane Hathaway shane at zope.com
Fri Sep 26 17:21:07 EDT 2003


Update of /cvs-repository/Products/CompositePage/tests
In directory cvs.zope.org:/tmp/cvs-serv25375/tests

Added Files:
	__init__.py test_tool.py 
Log Message:
Added the CompositePage product.

CompositePage is like the PageDesign product, but simplified, and now based
on PDLib, a Javascript drag and drop / context menu library.



=== Added File Products/CompositePage/tests/__init__.py ===
"""CompositePage tests.
"""


=== Added File Products/CompositePage/tests/test_tool.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
# 
##############################################################################
"""Composite tool tests.

$Id: test_tool.py,v 1.1 2003/09/26 21:21:06 shane Exp $
"""

import unittest

import ZODB
from OFS.Folder import Folder
from Products.CompositePage.tool import CompositeTool
from Products.CompositePage.slot import Slot
from Products.CompositePage.interfaces import CompositeError



class ToolTests(unittest.TestCase):

    def setUp(self):
        self.root = Folder()
        self.root.getPhysicalPath = lambda: ()
        self.root.getPhysicalRoot = lambda: self.root
        self.root.composite_tool = CompositeTool()
        self.tool = self.root.composite_tool
        self.root.slot = Slot("slot")
        self.slot = self.root.slot
        f = Folder()
        f._setId("f")
        self.slot._setObject(f.id, f)
        g = Folder()
        g._setId("g")
        self.slot._setObject(g.id, g)
        self.root.otherslot = Slot("otherslot")


    def testPreventParentageLoop(self):
        self.assertRaises(CompositeError, self.tool.moveElements,
                          ["/slot/foo"], "/slot/foo/zzz", 0)
        self.assertRaises(CompositeError, self.tool.moveElements,
                          ["/foo/bar"], "/foo/bar/baz/zip", 0)

    def testDelete(self):
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])
        self.tool.deleteElements(["/slot/g"])
        self.assertEqual(list(self.slot.objectIds()), ["f"])

    def testMoveWithinSlot(self):
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])
        self.tool.moveElements(["/slot/g"], "/slot", 0)
        self.assertEqual(list(self.slot.objectIds()), ["g", "f"])
        self.tool.moveElements(["/slot/g"], "/slot", 2)
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])
        self.tool.moveElements(["/slot/g"], "/slot", 1)
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])

    def testMoveToOtherSlot(self):
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])
        self.tool.moveElements(["/slot/f"], "/otherslot", 0)
        self.assertEqual(list(self.slot.objectIds()), ["g"])
        self.assertEqual(list(self.root.otherslot.objectIds()), ["f"])
        self.tool.moveElements(["/slot/g"], "/otherslot", 0)
        self.assertEqual(list(self.slot.objectIds()), [])
        self.assertEqual(list(self.root.otherslot.objectIds()), ["g", "f"])
        self.tool.moveElements(["/otherslot/f", "/otherslot/g"], "/slot", 0)
        # The new order is deterministic because of sorting in moveElements().
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])
        self.assertEqual(list(self.root.otherslot.objectIds()), [])

    def testMoveAndDelete(self):
        self.assertEqual(list(self.slot.objectIds()), ["f", "g"])
        self.assertEqual(list(self.root.otherslot.objectIds()), [])
        self.tool.moveAndDelete(move_source_paths="/slot/f:/slot/g",
                                move_target_path="/otherslot",
                                move_target_index="2")
        self.assertEqual(list(self.slot.objectIds()), [])
        self.assertEqual(list(self.root.otherslot.objectIds()), ["f", "g"])
        self.tool.moveAndDelete(
            delete_source_paths="/otherslot/f:/otherslot/g")
        self.assertEqual(list(self.slot.objectIds()), [])
        self.assertEqual(list(self.root.otherslot.objectIds()), [])


if __name__ == "__main__":
    unittest.main()





More information about the Zope-CVS mailing list