def testRemoveContainerProperty(self): container = BeanItemContainer(Person) john = Person('John') container.addBean(john) self.assertEquals('John', container.getContainerProperty(john, 'name').getValue()) self.assertTrue(container.removeContainerProperty('name')) self.assertEquals(container.getContainerProperty(john, 'name'), None) self.assertNotEquals(container.getItem(john), None) # property removed also from item self.assertEquals(container.getItem(john).getItemProperty('name'), None)
def testContainerOrdered(self): container = BeanItemContainer(str) idd = 'test1' item = container.addBean(idd) self.assertNotEquals(item, None) self.assertEquals(idd, container.firstItemId()) self.assertEquals(idd, container.lastItemId()) # isFirstId self.assertTrue(container.isFirstId(idd)) self.assertTrue(container.isFirstId(container.firstItemId())) # isLastId self.assertTrue(container.isLastId(idd)) self.assertTrue(container.isLastId(container.lastItemId())) # Add a new item before the first # addItemAfter newFirstId = 'newFirst' item = container.addItemAfter(None, newFirstId) self.assertNotEquals(item, None) self.assertNotEquals(container.getItem(newFirstId), None) # isFirstId self.assertTrue(container.isFirstId(newFirstId)) self.assertTrue(container.isFirstId(container.firstItemId())) # isLastId self.assertTrue(container.isLastId(idd)) self.assertTrue(container.isLastId(container.lastItemId())) # nextItemId self.assertEquals(idd, container.nextItemId(newFirstId)) self.assertEquals(container.nextItemId(idd), None) self.assertEquals(container.nextItemId('not-in-container'), None) # prevItemId self.assertEquals(newFirstId, container.prevItemId(idd)) self.assertEquals(container.prevItemId(newFirstId), None) self.assertEquals(container.prevItemId('not-in-container'), None) # addItemAfter(Object) newSecondItemId = 'newSecond' item = container.addItemAfter(newFirstId, newSecondItemId) # order is now: newFirstId, newSecondItemId, idd self.assertNotEquals(item, None) self.assertNotEquals(container.getItem(newSecondItemId), None) self.assertEquals(idd, container.nextItemId(newSecondItemId)) self.assertEquals(newFirstId, container.prevItemId(newSecondItemId)) # addItemAfter(Object,Object) fourthId = 'idd of the fourth item' fourth = container.addItemAfter(newFirstId, fourthId) # order is now: newFirstId, fourthId, newSecondItemId, idd self.assertNotEquals(fourth, None) self.assertEquals(fourth, container.getItem(fourthId)) self.assertEquals(newSecondItemId, container.nextItemId(fourthId)) self.assertEquals(newFirstId, container.prevItemId(fourthId)) # addItemAfter(Object,Object) fifthId = 'fifth' fifth = container.addItemAfter(None, fifthId) # order is now: fifthId, newFirstId, fourthId, newSecondItemId, idd self.assertNotEquals(fifth, None) self.assertEquals(fifth, container.getItem(fifthId)) self.assertEquals(newFirstId, container.nextItemId(fifthId)) self.assertEquals(container.prevItemId(fifthId), None)