Esempio n. 1
0
    def testUnsupportedMethods(self):
        container = BeanContainer(Person)
        container.addItem('John', Person('John'))

        try:
            container.addItem()
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        try:
            container.addItem(None)
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        try:
            container.addItemAfter(None, None)
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        try:
            container.addItemAfter(Person('Jane'))
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        try:
            container.addItemAt(0)
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        try:
            container.addItemAt(0, Person('Jane'))
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        try:
            container.addContainerProperty('lastName', str, '')
            self.fail()
        except NotImplementedError:
            pass  # should get exception

        self.assertEquals(1, len(container))
Esempio n. 2
0
    def testAddNullBeans(self):
        container = BeanContainer(Person)

        self.assertEquals(container.addItem('id1', None), None)
        self.assertEquals(container.addItemAfter(None, 'id2', None), None)
        self.assertEquals(container.addItemAt(0, 'id3', None), None)

        self.assertEquals(0, len(container))
Esempio n. 3
0
    def testAddNullId(self):
        container = BeanContainer(Person)

        john = Person('John')

        self.assertEquals(container.addItem(None, john), None)
        self.assertEquals(container.addItemAfter(None, None, john), None)
        self.assertEquals(container.addItemAt(0, None, john), None)

        self.assertEquals(0, len(container))
Esempio n. 4
0
    def testContainerOrdered(self):
        # TODO test IIndexed interface operation - testContainerIndexed()?
        container = BeanContainer(str)

        idd = 'test1'

        item = container.addItem(idd, 'value')
        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, 'newFirstValue')
        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(IDTYPE, IDTYPE, BT)
        newSecondItemId = 'newSecond'
        item = container.addItemAfter(newFirstId, newSecondItemId,
                'newSecondValue')
        # 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(IDTYPE, IDTYPE, BT)
        fourthId = 'idd of the fourth item'
        fourth = container.addItemAfter(newFirstId, fourthId, 'fourthValue')
        # 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(IDTYPE, IDTYPE, BT)
        fifthId = 'fifth'
        fifth = container.addItemAfter(None, fifthId, 'fifthValue')
        # 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)