Esempio n. 1
0
    def test_container_site(self):
        sm = SiteManagerStub()
        futurama = self.futurama
        omicronpersei = self.futurama['omicronpersei']

        # test behaviour before and after setting a site
        adapter = IChildObjects(futurama)
        self.assertTrue(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), list(futurama.values()))
        futurama.setSiteManager(sm)
        self.assertIn(sm, adapter.getChildObjects())

        adapter = IChildObjects(omicronpersei)
        self.assertFalse(adapter.hasChildren())
        omicronpersei.setSiteManager(sm)
        self.assertTrue(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), [sm])
Esempio n. 2
0
    def test_stub_adapters(self):
        # test content unique id
        farnesworth = SampleContent()
        elzar = SampleContent()
        adapter = IUniqueId(farnesworth)
        adapter2 = IUniqueId(elzar)
        self.assertNotEqual(adapter.getId(), 'farnesworth')
        self.assertNotEqual(adapter2.getId(), 'elzar')
        # test for uniqueness
        self.assertNotEqual(adapter.getId(), adapter2.getId())

        # test content child objects
        adapter = IChildObjects(elzar)
        self.assertFalse(adapter.hasChildren())
        self.assertEqual(len(adapter.getChildObjects()), 0)
        # test with acquired content
        bender = self.futurama['planetexpress']['bender']
        adapter = IChildObjects(bender)
        self.assertFalse(adapter.hasChildren())
        self.assertEqual(len(adapter.getChildObjects()), 0)
Esempio n. 3
0
    def test_container_childobjects(self):
        # test container with children
        futurama = self.futurama
        adapter = IChildObjects(futurama)
        self.assert_(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), futurama.values())

        # test acquired container with children
        planetexpress = self.futurama["planetexpress"]
        adapter = IChildObjects(planetexpress)
        self.assert_(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), planetexpress.values())

        # test acquired container w/o children
        omicronpersei = self.futurama["omicronpersei"]
        adapter = IChildObjects(omicronpersei)
        self.failIf(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), [])
Esempio n. 4
0
    def test_container_site(self):
        sm = SiteManagerStub()
        futurama = self.futurama
        omicronpersei = self.futurama["omicronpersei"]

        # test behaviour before and after setting a site
        adapter = IChildObjects(futurama)
        self.assert_(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), futurama.values())
        futurama.setSiteManager(sm)
        self.assert_(sm in adapter.getChildObjects())

        adapter = IChildObjects(omicronpersei)
        self.failIf(adapter.hasChildren())
        omicronpersei.setSiteManager(sm)
        self.assert_(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), [sm])
Esempio n. 5
0
    def test_container_childobjects(self):
        # test container with children
        futurama = self.futurama
        adapter = IChildObjects(futurama)
        self.assertTrue(adapter.hasChildren())
        self.assertEqual(list(adapter.getChildObjects()),
                         list(futurama.values()))

        # test acquired container with children
        planetexpress = self.futurama['planetexpress']
        adapter = IChildObjects(planetexpress)
        self.assertTrue(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(),
                         list(planetexpress.values()))

        # test acquired container w/o children
        omicronpersei = self.futurama['omicronpersei']
        adapter = IChildObjects(omicronpersei)
        self.assertFalse(adapter.hasChildren())
        self.assertEqual(adapter.getChildObjects(), [])
Esempio n. 6
0
 def _get_child_objects_adapter(self):
     """Lazily create the child objects adapter"""
     if self._child_objects_adapter is None:
         self._child_objects_adapter = IChildObjects(self.context)
     return self._child_objects_adapter