Exemplo n.º 1
0
    def test_comparedbdatasource(self):
        """ Test same name function """

        # differ only by pk
        ds1 = "dbname='comune_capannori' host=0.0.0.0 port=5432 user='******' password='******' sslmode=disable key='gid' srid=3003 type=MultiPolygon table=\"dati_catastali\".\"catasto\" (geom) sql="
        ds2 = "dbname='comune_capannori' host=0.0.0.0 port=5432 user='******' password='******' sslmode=disable key='id' srid=3003 type=MultiPolygon table=\"dati_catastali\".\"catasto\" (geom) sql="

        self.assertTrue(comparedbdatasource(ds1, ds2))

        # differ by host and pk
        ds1 = "dbname='comune_capannori' host=0.0.0.1 port=5432 user='******' password='******' sslmode=disable key='gid' srid=3003 type=MultiPolygon table=\"dati_catastali\".\"catasto\" (geom) sql="
        ds2 = "dbname='comune_capannori' host=0.0.0.0 port=5432 user='******' password='******' sslmode=disable key='id' srid=3003 type=MultiPolygon table=\"dati_catastali\".\"catasto\" (geom) sql="

        self.assertFalse(comparedbdatasource(ds1, ds2))

        # for sqlite dsources:
        ds1 = "dbname='/home/www/g3w_suite_data/dati_geografici/editing_test.db' table=\"cities\" (geometry) sql="
        ds2 = "dbname='/home/www/g3w_suite_data/dati_geografici/editing_test.db' table=\"cities\" (geometry) sql="

        self.assertTrue(comparedbdatasource(ds1, ds2, 'spatialite'))

        # for sqlite dsources:
        # differ by table name
        ds1 = "dbname='/home/www/g3w_suite_data/dati_geografici/editing_test.db' table=\"cities\" (geometry) sql="
        ds2 = "dbname='/home/www/g3w_suite_data/dati_geografici/editing_test.db' table=\"citiesxxx\" (geometry) sql="

        self.assertFalse(comparedbdatasource(ds1, ds2, 'spatialite'))

        # for sqlite dsources:
        # differ by sqlite
        ds1 = "dbname='/home/www/g3w_suite_data/dati_geografici/editing_test.db' table=\"cities\" (geometry) sql="
        ds2 = "dbname='/home/www/g3w_suite_data/dati_geografici/editing_test.db' table=\"cities\" (geometry) sql='name=\"xxxx\"'"

        self.assertTrue(comparedbdatasource(ds1, ds2, 'spatialite'))
Exemplo n.º 2
0
    def linkUnlinkWidget(self, link=True):

        # apply check datasourc only for postgres and spatialite
        if self.layer.layer_type in ('postgres', 'spatialite') \
                and not comparedbdatasource(self.layer.datasource, self.widget.datasource, self.layer.layer_type):
            raise Exception(
                'Datasource of widget is different from layer datasource')
        if link:
            self.widget.layers.add(self.layer)
        else:
            self.widget.layers.remove(self.layer)