Exemple #1
0
    def showImportDlg(self):
        from safe_qgis.import_dialog import ImportDialog

        dlg = ImportDialog(self.iface.mainWindow(), self.iface)
        dlg.setModal(True)
        dlg.show()
Exemple #2
0
    def setUp(self):
        self.importDlg = ImportDialog(PARENT, IFACE)

        ## provide Fake QNetworkAccessManager for self.nam
        self.importDlg.nam = FakeQNetworkAccessManager()
Exemple #3
0
class ImportDialogTest(unittest.TestCase):
    """Test Import Dialog widget
    """
    def test_httpDownload(self):
        myManager = QNetworkAccessManager(PARENT)

        # NOTE(gigih):
        # this is the hash of google front page.
        # I think we can safely assume that the content
        # of google.com never changes (probably).
        #
        myHash = 'd4b691cd9d99117b2ea34586d3e7eeb8'
        myUrl = 'http://google.com'
        myTempFilePath = tempfile.mktemp()

        httpDownload(myManager, myUrl, myTempFilePath)

        assertHashForFile(myHash, myTempFilePath)

    def setUp(self):
        self.importDlg = ImportDialog(PARENT, IFACE)

        ## provide Fake QNetworkAccessManager for self.nam
        self.importDlg.nam = FakeQNetworkAccessManager()

    def test_downloadShapeFile(self):
        myUrl = 'http://osm.linfiniti.com/buildings-shp?' + \
                'bbox=20.389938354492188,-34.10782492987083' \
                ',20.712661743164062,' + \
                '-34.008273470938335&obj=building'
        myTempFilePath = tempfile.mktemp('shapefiles')
        self.importDlg.downloadShapeFile(myUrl, myTempFilePath)

        myMessage = "file %s not exist" % myTempFilePath
        assert os.path.exists(myTempFilePath), myMessage

        # cleanup
        os.remove(myTempFilePath)

    def test_extractZip(self):
        myInput = os.path.join(TEST_DATA_DIR, 'test-importdlg-extractzip.zip')
        myOutDir = tempfile.mkdtemp()

        self.importDlg.extractZip(myInput, myOutDir)

        myMessage = "file {0} not exist"

        myFile = 'planet_osm_line.shp'
        myPath = os.path.join(myOutDir, myFile)
        assert os.path.exists(myPath), myMessage.format(myFile)

        myFile = 'planet_osm_point.shp'
        myPath = os.path.join(myOutDir, myFile)
        assert os.path.exists(myPath), myMessage.format(myFile)

        myFile = 'planet_osm_polygon.shp'
        myPath = os.path.join(myOutDir, myFile)
        assert os.path.exists(myPath), myMessage.format(myFile)

        # remove temporary folder and all of its content
        shutil.rmtree(myOutDir)

    def test_doImport(self):
        myOutDir = tempfile.mkdtemp()
        self.importDlg.outDir.setText(myOutDir)
        self.importDlg.minLongitude.setText('20.389938354492188')
        self.importDlg.minLatitude.setText('-34.10782492987083')
        self.importDlg.maxLongitude.setText('20.712661743164062')
        self.importDlg.maxLatitude.setText('-34.008273470938335')
        self.importDlg.cbxPreset.setCurrentIndex(1)  # buildings
        self.importDlg.doImport()

        myResult = self.importDlg.progressDialog.result()
        myMessage = "result dont match. current result is %s " % myResult
        assert myResult == QDialog.Accepted, myMessage

    def test_loadShapeFile(self):
        """ test loading shape file to QGIS Main Window """

        myInput = os.path.join(TEST_DATA_DIR, 'test-importdlg-extractzip.zip')
        myOutDir = tempfile.mkdtemp()

        self.importDlg.extractZip(myInput, myOutDir)

        # outDir must be set to myOutDir because loadShapeFile() use
        # that variable to determine the location of shape files.
        self.importDlg.outDir.setText(myOutDir)

        self.importDlg.loadShapeFile()

        #FIXME(gigih): need to check if layer is loaded to QGIS

        # remove temporary folder and all of its content
        shutil.rmtree(myOutDir)
Exemple #4
0
    def setUp(self):
        self.importDlg = ImportDialog(PARENT, IFACE)

        ## provide Fake QNetworkAccessManager for self.nam
        self.importDlg.nam = FakeQNetworkAccessManager()
Exemple #5
0
class ImportDialogTest(unittest.TestCase):
    """Test Import Dialog widget
    """

    def test_httpDownload(self):
        myManager = QNetworkAccessManager(PARENT)

        # NOTE(gigih):
        # this is the hash of google front page.
        # I think we can safely assume that the content
        # of google.com never changes (probably).
        #
        myHash = "d4b691cd9d99117b2ea34586d3e7eeb8"
        myUrl = "http://google.com"
        myTempFilePath = tempfile.mktemp()

        httpDownload(myManager, myUrl, myTempFilePath)

        assertHashForFile(myHash, myTempFilePath)

    def setUp(self):
        self.importDlg = ImportDialog(PARENT, IFACE)

        ## provide Fake QNetworkAccessManager for self.nam
        self.importDlg.nam = FakeQNetworkAccessManager()

    def test_downloadShapeFile(self):
        myUrl = (
            "http://osm.linfiniti.com/buildings-shp?" + "bbox=20.389938354492188,-34.10782492987083"
            ",20.712661743164062," + "-34.008273470938335&obj=building"
        )
        myTempFilePath = tempfile.mktemp("shapefiles")
        self.importDlg.downloadShapeFile(myUrl, myTempFilePath)

        myMessage = "file %s not exist" % myTempFilePath
        assert os.path.exists(myTempFilePath), myMessage

        # cleanup
        os.remove(myTempFilePath)

    def test_extractZip(self):
        myInput = os.path.join(TEST_DATA_DIR, "test-importdlg-extractzip.zip")
        myOutDir = tempfile.mkdtemp()

        self.importDlg.extractZip(myInput, myOutDir)

        myMessage = "file {0} not exist"

        myFile = "planet_osm_line.shp"
        myPath = os.path.join(myOutDir, myFile)
        assert os.path.exists(myPath), myMessage.format(myFile)

        myFile = "planet_osm_point.shp"
        myPath = os.path.join(myOutDir, myFile)
        assert os.path.exists(myPath), myMessage.format(myFile)

        myFile = "planet_osm_polygon.shp"
        myPath = os.path.join(myOutDir, myFile)
        assert os.path.exists(myPath), myMessage.format(myFile)

        # remove temporary folder and all of its content
        shutil.rmtree(myOutDir)

    def test_doImport(self):
        myOutDir = tempfile.mkdtemp()
        self.importDlg.outDir.setText(myOutDir)
        self.importDlg.minLongitude.setText("20.389938354492188")
        self.importDlg.minLatitude.setText("-34.10782492987083")
        self.importDlg.maxLongitude.setText("20.712661743164062")
        self.importDlg.maxLatitude.setText("-34.008273470938335")
        self.importDlg.cbxPreset.setCurrentIndex(1)  # buildings
        self.importDlg.doImport()

        myResult = self.importDlg.progressDialog.result()
        myMessage = "result dont match. current result is %s " % myResult
        assert myResult == QDialog.Accepted, myMessage

    def test_loadShapeFile(self):
        """ test loading shape file to QGIS Main Window """

        myInput = os.path.join(TEST_DATA_DIR, "test-importdlg-extractzip.zip")
        myOutDir = tempfile.mkdtemp()

        self.importDlg.extractZip(myInput, myOutDir)

        # outDir must be set to myOutDir because loadShapeFile() use
        # that variable to determine the location of shape files.
        self.importDlg.outDir.setText(myOutDir)

        self.importDlg.loadShapeFile()

        # FIXME(gigih): need to check if layer is loaded to QGIS

        # remove temporary folder and all of its content
        shutil.rmtree(myOutDir)
Exemple #6
0
    def showImportDlg(self):
        from safe_qgis.import_dialog import ImportDialog

        dlg = ImportDialog(self.iface.mainWindow(), self.iface)
        dlg.setModal(True)
        dlg.show()