class VHMAddingTests(unittest.TestCase):

    def setUp(self):
        from OFS.Folder import Folder
        super(VHMAddingTests, self).setUp()
        self.root = Folder('root')

    def _makeOne(self):
        from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
        return VirtualHostMonster()

    def test_add_with_existing_vhm(self):
        from Products.SiteAccess.VirtualHostMonster import \
            manage_addVirtualHostMonster
        from zExceptions import BadRequest
        vhm1 = self._makeOne()
        vhm1.manage_addToContainer(self.root)

        vhm2 = self._makeOne()
        self.assertRaises(BadRequest, vhm2.manage_addToContainer, self.root)
        self.assertRaises( BadRequest
                         , manage_addVirtualHostMonster
                         , self.root
                         )

    def test_add_id_collision(self):
        from OFS.Folder import Folder
        from Products.SiteAccess.VirtualHostMonster import \
            manage_addVirtualHostMonster
        from zExceptions import BadRequest
        self.root._setObject('VHM', Folder('VHM'))
        vhm1 = self._makeOne()

        self.assertRaises(BadRequest, vhm1.manage_addToContainer, self.root)
        self.assertRaises( BadRequest
                         , manage_addVirtualHostMonster
                         , self.root
                         )

    def test_add_addToContainer(self):
        from ZPublisher.BeforeTraverse import queryBeforeTraverse
        vhm1 = self._makeOne()
        vhm1.manage_addToContainer(self.root)

        self.assertTrue(vhm1.getId() in self.root.objectIds())
        self.assertTrue(queryBeforeTraverse(self.root, vhm1.meta_type))

    def test_add_manage_addVirtualHostMonster(self):
        from Products.SiteAccess.VirtualHostMonster import \
            manage_addVirtualHostMonster
        from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
        from ZPublisher.BeforeTraverse import queryBeforeTraverse
        manage_addVirtualHostMonster(self.root)

        self.assertTrue(VirtualHostMonster.id in self.root.objectIds())
        hook = queryBeforeTraverse(self.root, VirtualHostMonster.meta_type)
        self.assertTrue(hook)
Exemple #2
0
class VHMAddingTests(unittest.TestCase):

    def setUp(self):
        from OFS.Folder import Folder
        super(VHMAddingTests, self).setUp()
        self.root = Folder('root')

    def _makeOne(self):
        from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
        return VirtualHostMonster()

    def test_add_with_existing_vhm(self):
        from Products.SiteAccess.VirtualHostMonster import \
            manage_addVirtualHostMonster
        from zExceptions import BadRequest
        vhm1 = self._makeOne()
        vhm1.manage_addToContainer(self.root)

        vhm2 = self._makeOne()
        self.assertRaises(BadRequest, vhm2.manage_addToContainer, self.root)
        self.assertRaises( BadRequest
                         , manage_addVirtualHostMonster
                         , self.root
                         )

    def test_add_id_collision(self):
        from OFS.Folder import Folder
        from Products.SiteAccess.VirtualHostMonster import \
            manage_addVirtualHostMonster
        from zExceptions import BadRequest
        self.root._setObject('VHM', Folder('VHM'))
        vhm1 = self._makeOne()

        self.assertRaises(BadRequest, vhm1.manage_addToContainer, self.root)
        self.assertRaises( BadRequest
                         , manage_addVirtualHostMonster
                         , self.root
                         )

    def test_add_addToContainer(self):
        from ZPublisher.BeforeTraverse import queryBeforeTraverse
        vhm1 = self._makeOne()
        vhm1.manage_addToContainer(self.root)

        self.assertTrue(vhm1.getId() in self.root.objectIds())
        self.assertTrue(queryBeforeTraverse(self.root, vhm1.meta_type))

    def test_add_manage_addVirtualHostMonster(self):
        from Products.SiteAccess.VirtualHostMonster import \
            manage_addVirtualHostMonster
        from Products.SiteAccess.VirtualHostMonster import VirtualHostMonster
        from ZPublisher.BeforeTraverse import queryBeforeTraverse
        manage_addVirtualHostMonster(self.root)

        self.assertTrue(VirtualHostMonster.id in self.root.objectIds())
        hook = queryBeforeTraverse(self.root, VirtualHostMonster.meta_type)
        self.assertTrue(hook)
 def testAllowGroupsAttribute(self):
     # Verify that __allow_groups__ gets set and removed
     from OFS.Folder import Folder
     f = Folder()
     zcuf = self._makeOne()
     f._setObject(zcuf.getId(), zcuf)
     self.assert_(zcuf.getId() in f.objectIds())
     self.assert_(aq_base(f.__allow_groups__) is aq_base(f.acl_users))
     f._delObject(zcuf.getId())
     self.assert_(not zcuf.getId() in f.objectIds())
 def testAllowGroupsAttribute(self):
     # Verify that __allow_groups__ gets set and removed
     from OFS.Folder import Folder
     f = Folder()
     zcuf = self._makeOne()
     f._setObject(zcuf.getId(), zcuf)
     self.assert_(zcuf.getId() in f.objectIds())
     self.assert_(aq_base(f.__allow_groups__) is aq_base(f.acl_users))
     f._delObject(zcuf.getId())
     self.assert_(not zcuf.getId() in f.objectIds())
Exemple #5
0
    def objectIds(self, spec=None):
        """ this is a patch for pre-2.4 Zope installations. Such
            installations don't have an entry for the WebDAV LockManager
            introduced in 2.4.
        """

        meta_types = map(lambda x: x.get('meta_type',None) , self._objects)

        if not self.DavLocks.meta_type in meta_types:

            lst = list(self._objects)
            lst.append(  {'id': 'DavLocks', \
                'meta_type': self.DavLocks.meta_type})
            self._objects = tuple(lst)

        return Folder.objectIds(self, spec)
    def objectIds(self, spec=None):
        """ this is a patch for pre-2.4 Zope installations. Such
            installations don't have an entry for the WebDAV LockManager
            introduced in 2.4.
        """

        meta_types = map(lambda x: x.get('meta_type',None) , self._objects)

        if not self.DavLocks.meta_type in meta_types:

            lst = list(self._objects)
            lst.append(  {'id': 'DavLocks', \
                'meta_type': self.DavLocks.meta_type})
            self._objects = tuple(lst)

        return Folder.objectIds(self, spec)
class TestOrderFolder(unittest.TestCase):

    def setUp(self):
        self.folder = Folder('folder1')
        manage_addFolder(self.folder, 'folder11')
        manage_addFolder(self.folder, 'folder12')
        manage_addFolder(self.folder, 'folder13')
        self.db = DB(MappingStorage())
        self.connection = self.db.open()

    def tearDown(self):
        self.db.close()

    def test_basic(self):
        """ Let's create a folder with a few objects and change their order """
        order_seq = ['folder11', 'folder13', 'folder12']
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(), order_seq)

    def test_unchanged(self):
        """ Nothing changes """
        order_seq = self.folder.objectIds()
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(), order_seq)

    def test_incomplete(self):
        """ Some ids from the folder are missing in the call. This means that
        the folder must be reordered and the missing ids must be put at the
        end."""

        order_seq = ['folder13', 'folder12']
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(), order_seq + ['folder11'])

    def test_extra_id(self):
        """ An ID that is not inside the folder """

        order_seq = ['folder13', 'asdf']
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(),
                         ['folder13', 'folder11', 'folder12'])

    def test_no_unnecessary_commit(self):
        order_seq = self.folder.objectIds()
        folderutils.sort_folder(self.folder, order_seq)

        root = self.connection.root()
        root['folder'] = self.folder
        transaction.commit()

        order_seq.pop() # resulting order should be the same
        folderutils.sort_folder(self.folder, order_seq)
        # assert no commit to DB since no change was required by ordering
        self.assertEqual(self.connection._registered_objects, [])
Exemple #8
0
class TestOrderFolder(unittest.TestCase):
    def setUp(self):
        self.folder = Folder('folder1')
        manage_addFolder(self.folder, 'folder11')
        manage_addFolder(self.folder, 'folder12')
        manage_addFolder(self.folder, 'folder13')
        self.db = DB(MappingStorage())
        self.connection = self.db.open()

    def tearDown(self):
        self.db.close()

    def test_basic(self):
        """ Let's create a folder with a few objects and change their order """
        order_seq = ['folder11', 'folder13', 'folder12']
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(), order_seq)

    def test_unchanged(self):
        """ Nothing changes """
        order_seq = self.folder.objectIds()
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(), order_seq)

    def test_incomplete(self):
        """ Some ids from the folder are missing in the call. This means that
        the folder must be reordered and the missing ids must be put at the
        end."""

        order_seq = ['folder13', 'folder12']
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(), order_seq + ['folder11'])

    def test_extra_id(self):
        """ An ID that is not inside the folder """

        order_seq = ['folder13', 'asdf']
        folderutils.sort_folder(self.folder, order_seq)
        self.assertEqual(self.folder.objectIds(),
                         ['folder13', 'folder11', 'folder12'])

    def test_no_unnecessary_commit(self):
        order_seq = self.folder.objectIds()
        folderutils.sort_folder(self.folder, order_seq)

        root = self.connection.root()
        root['folder'] = self.folder
        transaction.commit()

        order_seq.pop()  # resulting order should be the same
        folderutils.sort_folder(self.folder, order_seq)
        # assert no commit to DB since no change was required by ordering
        self.assertEqual(self.connection._registered_objects, [])