Esempio n. 1
0
    def test_addRelation(self):
        """ test adding relations to a manager """
        manager = QgsRelationManager()

        relations = manager.relations()
        self.assertEqual(len(relations), 0)

        rel = self.createRelation()
        rel.setId('rel1')
        rel.setName('Relation Number One')
        assert rel.isValid()

        manager.addRelation(rel)

        relations = manager.relations()
        self.assertEqual(len(relations), 1)
        self.assertEqual(relations['rel1'].id(), 'rel1')

        rel = self.createRelation()
        rel.setId('rel2')
        rel.setName('Relation Number Two')
        assert rel.isValid()

        manager.addRelation(rel)

        relations = manager.relations()
        self.assertEqual(len(relations), 2)
        ids = [r.id() for r in list(relations.values())]
        self.assertEqual(set(ids), set(['rel1', 'rel2']))
Esempio n. 2
0
    def test_addRelation(self):
        """ test adding relations to a manager """
        manager = QgsRelationManager()

        relations = manager.relations()
        self.assertEqual(len(relations), 0)

        rel = self.createRelation()
        rel.setRelationId('rel1')
        rel.setRelationName('Relation Number One')
        assert rel.isValid()

        manager.addRelation(rel)

        relations = manager.relations()
        self.assertEqual(len(relations), 1)
        self.assertEqual(relations['rel1'].id(), 'rel1')

        rel = self.createRelation()
        rel.setRelationId('rel2')
        rel.setRelationName('Relation Number Two')
        assert rel.isValid()

        manager.addRelation(rel)

        relations = manager.relations()
        self.assertEqual(len(relations), 2)
        ids = [r.id() for r in list(relations.values())]
        self.assertEqual(set(ids), set(['rel1', 'rel2']))
Esempio n. 3
0
    def test_removePolymorphicRelation(self):
        # tests addPolymorphicRelation/removePolymorphicRelation

        manager = QgsRelationManager()

        # initially the map should be empty
        self.assertFalse(manager.polymorphicRelations())
        self.assertFalse(manager.relations())

        poly_rel1 = self.createPolymorphicRelation()
        poly_rel1.setId('poly_rel1')
        poly_rel1.setName('Poly Rel 1')
        poly_rel2 = self.createPolymorphicRelation()
        poly_rel2.setId('poly_rel2')
        poly_rel2.setName('Poly Rel 2')

        # the relation should be valid now
        self.assertTrue(poly_rel1.isValid())
        self.assertTrue(poly_rel2.isValid())
        self.assertFalse(
            manager.polymorphicRelation('poly_invalid_id').isValid())
        self.assertListEqual(
            [r.polymorphicRelationId() for r in manager.relations().values()],
            [])

        manager.addPolymorphicRelation(poly_rel1)
        self.assertTrue(manager.polymorphicRelation('poly_rel1').isValid())
        self.assertTrue(
            manager.polymorphicRelation('poly_rel1').hasEqualDefinition(
                poly_rel1))
        self.assertListEqual(
            [r.polymorphicRelationId() for r in manager.relations().values()],
            [poly_rel1.id()])

        manager.addPolymorphicRelation(poly_rel2)
        self.assertTrue(manager.polymorphicRelation('poly_rel2').isValid())
        self.assertTrue(
            manager.polymorphicRelation('poly_rel2').hasEqualDefinition(
                poly_rel2))
        self.assertListEqual(
            [r.polymorphicRelationId() for r in manager.relations().values()],
            [poly_rel1.id(), poly_rel2.id()])

        manager.removePolymorphicRelation(poly_rel1.id())
        self.assertFalse(manager.polymorphicRelation('poly_rel1').isValid())
        self.assertTrue(manager.polymorphicRelation('poly_rel2').isValid())
        self.assertListEqual(
            [r.polymorphicRelationId() for r in manager.relations().values()],
            [poly_rel2.id()])
        manager.removePolymorphicRelation(poly_rel2.id())
        self.assertFalse(manager.polymorphicRelation('poly_rel1').isValid())
        self.assertFalse(manager.polymorphicRelation('poly_rel2').isValid())
        self.assertListEqual(
            [r.polymorphicRelationId() for r in manager.relations().values()],
            [])