Ejemplo 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))
Ejemplo 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))
Ejemplo 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))
Ejemplo n.º 4
0
    def testAddItemAt(self):
        container = BeanContainer(str)

        container.addItem('id1', 'value1')
        # id1
        container.addItemAt(0, 'id2', 'value2')
        # id2, id1
        container.addItemAt(1, 'id3', 'value3')
        # id2, id3, id1
        container.addItemAt(len(container), 'id4', 'value4')
        # id2, id3, id1, id4

        self.assertEquals(container.addItemAt(-1, 'id5', 'value5'), None)
        self.assertEquals(container.addItemAt(len(container) + 1, 'id6',
                'value6'), None)

        self.assertEquals(4, len(container))
        self.assertEquals('id2', container.getIdByIndex(0))
        self.assertEquals('id3', container.getIdByIndex(1))
        self.assertEquals('id1', container.getIdByIndex(2))
        self.assertEquals('id4', container.getIdByIndex(3))