Пример #1
0
    def testAddBeanWithNullResolver(self):
        container = BeanContainer(Person)

        # resolver that returns null as item id
        container.setBeanIdResolver(self.NullResolver())

        try:
            container.addBean(Person('John'))
            self.fail()
        except ValueError:
            pass  # should get exception

        try:
            container.addBeanAfter(None, Person('Jane'))
            self.fail()
        except ValueError:
            pass  # should get exception

        try:
            container.addBeanAt(0, Person('Jack'))
            self.fail()
        except ValueError:
            pass  # should get exception

        self.assertEquals(0, len(container))
Пример #2
0
    def testAddNullBeansWithResolver(self):
        container = BeanContainer(Person)
        container.setBeanIdResolver(PersonNameResolver())

        self.assertEquals(container.addBean(None), None)
        self.assertEquals(container.addBeanAfter(None, None), None)
        self.assertEquals(container.addBeanAt(0, None), None)

        self.assertEquals(0, len(container))
Пример #3
0
    def testRemoveContainerProperty(self):
        container = BeanContainer(Person)
        container.setBeanIdResolver(self.PersonNameResolver())
        container.addBean(Person('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)
Пример #4
0
    def testAddBeanWithResolver(self):
        container = BeanContainer(Person)
        container.setBeanIdResolver(self.PersonNameResolver())

        self.assertNotEquals(container.addBean(Person('John')), None)
        self.assertNotEquals(container.addBeanAfter(None, Person('Jane')), None)
        self.assertNotEquals(container.addBeanAt(0, Person('Jack')), None)

        container.addAll( [Person('Jill'), Person('Joe')] )

        self.assertTrue(container.containsId('John'))
        self.assertTrue(container.containsId('Jane'))
        self.assertTrue(container.containsId('Jack'))
        self.assertTrue(container.containsId('Jill'))
        self.assertTrue(container.containsId('Joe'))
        self.assertEquals(3, container.indexOfId('Jill'))
        self.assertEquals(4, container.indexOfId('Joe'))
        self.assertEquals(5, len(container))