コード例 #1
0
    def testDuplicateAttrNames(self):
        schemaWithEntityA = Schema()
        schemaWithEntityA.addEntity('A')
        schemaWithEntityA.addAttribute('A', 'X', Attribute.INTEGER)
        TestUtil.assertRaisesMessage(
            self, Exception,
            "Schema already has attribute named 'X' for item 'A'",
            schemaWithEntityA.addAttribute, 'A', 'X', Attribute.INTEGER)

        schemaWithEntityA.addEntity('B')
        schemaWithEntityA.addRelationship('AB', ('A', Schema.ONE),
                                          ('B', Schema.ONE))
        schemaWithEntityA.addAttribute('AB', 'XY', Attribute.INTEGER)
        TestUtil.assertRaisesMessage(
            self, Exception,
            "Schema already has attribute named 'XY' for item 'AB'",
            schemaWithEntityA.addAttribute, 'AB', 'XY', Attribute.INTEGER)

        a = schemaWithEntityA.getEntity('A')
        TestUtil.assertRaisesMessage(
            self, Exception,
            "Schema already has attribute named 'X' for item 'A'",
            a.addAttribute, 'X', Attribute.INTEGER)

        ab = schemaWithEntityA.getRelationship('AB')
        TestUtil.assertRaisesMessage(
            self, Exception,
            "Schema already has attribute named 'XY' for item 'AB'",
            ab.addAttribute, 'XY', Attribute.INTEGER)
コード例 #2
0
    def testGetEntity(self):
        schema = Schema()
        schema.addEntity('A')
        schema.addEntity('B')
        actualEntity = schema.getEntity('A')
        self.assertEqual('A', actualEntity.name)
        self.assertTrue(schema.hasEntity('A'))

        actualEntity = schema.getEntity('B')
        self.assertEqual('B', actualEntity.name)
        self.assertTrue(schema.hasEntity('B'))

        TestUtil.assertRaisesMessage(self, Exception,
                                     "Entity 'XX' does not exist",
                                     schema.getEntity, 'XX')
        self.assertFalse(schema.hasEntity('XX'))
コード例 #3
0
    def testAddEntityAttribute(self):
        a = Entity('A')
        a.addAttribute('X', Attribute.INTEGER)
        TestUtil.assertUnorderedListEqual(self, ['X'],
                                          [attr.name for attr in a.attributes])

        a.addAttribute('Y', Attribute.INTEGER)
        TestUtil.assertUnorderedListEqual(self, ['X', 'Y'],
                                          [attr.name for attr in a.attributes])

        schema = Schema()
        schema.addEntity('A')
        schema.addAttribute('A', 'X', Attribute.INTEGER)
        TestUtil.assertUnorderedListEqual(
            self, ['X'],
            [attr.name for attr in schema.getEntity('A').attributes])

        schema.addAttribute('A', 'Y', Attribute.INTEGER)
        TestUtil.assertUnorderedListEqual(
            self, ['X', 'Y'],
            [attr.name for attr in schema.getEntity('A').attributes])