Exemple #1
0
    def test_getConnectionString(self):

        obj = Ogr2OgrToPostGis()

        cs = obj.getConnectionString()
        # NOTE: defaults are debatable, see
        # https://github.com/qgis/QGIS/pull/3607#issuecomment-253971020
        self.assertEquals(obj.getConnectionString(),
                          "host=localhost port=5432 active_schema=public")

        obj.setParameterValue('HOST', 'remote')
        self.assertEquals(obj.getConnectionString(),
                          "host=remote port=5432 active_schema=public")

        obj.setParameterValue('HOST', '')
        self.assertEquals(obj.getConnectionString(),
                          "port=5432 active_schema=public")

        obj.setParameterValue('PORT', '5555')
        self.assertEquals(obj.getConnectionString(),
                          "port=5555 active_schema=public")

        obj.setParameterValue('PORT', '')
        self.assertEquals(obj.getConnectionString(), "active_schema=public")

        obj.setParameterValue('USER', 'usr')
        self.assertEquals(obj.getConnectionString(),
                          "active_schema=public user=usr")

        obj.setParameterValue('PASSWORD', 'pwd')
        self.assertEquals(obj.getConnectionString(),
                          "password=pwd active_schema=public user=usr")
    def test_getConnectionString(self):

        obj = Ogr2OgrToPostGis()

        parameters = {}

        # NOTE: defaults are debatable, see
        # https://github.com/qgis/QGIS/pull/3607#issuecomment-253971020
        self.assertEqual(obj.getConnectionString(parameters),
                         "host=localhost port=5432 active_schema=public")

        parameters['HOST'] = 'remote'
        self.assertEqual(obj.getConnectionString(parameters),
                         "host=remote port=5432 active_schema=public")

        parameters['HOST'] = ''
        self.assertEqual(obj.getConnectionString(parameters),
                         "port=5432 active_schema=public")

        parameters['PORT'] = '5555'
        self.assertEqual(obj.getConnectionString(parameters),
                         "port=5555 active_schema=public")

        parameters['PORT'] = ''
        self.assertEqual(obj.getConnectionString(parameters),
                         "active_schema=public")

        parameters['USER'] = '******'
        self.assertEqual(obj.getConnectionString(parameters),
                         "active_schema=public user=usr")

        parameters['PASSWORD'] = '******'
        self.assertEqual(obj.getConnectionString(parameters),
                         "password=pwd active_schema=public user=usr")