def show_osm_downloader(self): """Show the OSM buildings downloader dialog.""" from safe_qgis.tools.osm_downloader import OsmDownloader dialog = OsmDownloader(self.iface.mainWindow(), self.iface) dialog.setModal(True) dialog.show()
def showImportDlg(self): from safe_qgis.tools.osm_downloader import OsmDownloader dlg = OsmDownloader(self.iface.mainWindow(), self.iface) dlg.setModal(True) dlg.show()
def setUp(self): """Runs before each test.""" self.importDlg = OsmDownloader(PARENT, IFACE) ## provide Fake QNetworkAccessManager for self.network_manager self.importDlg.network_manager = FakeQNetworkAccessManager()
class ImportDialogTest(unittest.TestCase): """Test Import Dialog widget """ def setUp(self): """Runs before each test.""" self.importDlg = OsmDownloader(PARENT, IFACE) ## provide Fake QNetworkAccessManager for self.network_manager self.importDlg.network_manager = FakeQNetworkAccessManager() def test_download_url(self): """Test we can download a zip. Uses a mock network stack.""" 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() download_url(myManager, myUrl, myTempFilePath) assert_hash_for_file(myHash, myTempFilePath) def test_fetch_zip(self): """Test fetch zip method.""" myUrl = 'http://osm.linfiniti.com/buildings-shp?' + \ 'bbox=20.389938354492188,-34.10782492987083' \ ',20.712661743164062,' + \ '-34.008273470938335&obj=building' myTempFilePath = tempfile.mktemp('shapefiles') self.importDlg.fetch_zip(myUrl, myTempFilePath) myMessage = "file %s not exist" % myTempFilePath assert os.path.exists(myTempFilePath), myMessage # cleanup os.remove(myTempFilePath) def test_extract_zip(self): """Test extract_zip method.""" myOutDir = tempfile.mkdtemp() myInput = os.path.abspath(os.path.join( TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) self.importDlg.extract_zip(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_download(self): """Test download method.""" 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.download() myResult = self.importDlg.progressDialog.result() myMessage = "result do not match. current result is %s " % myResult assert myResult == QDialog.Accepted, myMessage def test_load_shapefile(self): """Test loading shape file to QGIS Main Window """ myInput = os.path.abspath(os.path.join( TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) myOutDir = tempfile.mkdtemp() self.importDlg.extract_zip(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.load_shapefile() #FIXME(gigih): need to check if layer is loaded to QGIS # remove temporary folder and all of its content shutil.rmtree(myOutDir)
class ImportDialogTest(unittest.TestCase): """Test Import Dialog widget """ def setUp(self): """Runs before each test.""" self.importDlg = OsmDownloader(PARENT, IFACE) ## provide Fake QNetworkAccessManager for self.network_manager self.importDlg.network_manager = FakeQNetworkAccessManager() def test_download_url(self): """Test we can download a zip. Uses a mock network stack.""" 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() download_url(myManager, myUrl, myTempFilePath) assert_hash_for_file(myHash, myTempFilePath) def test_fetch_zip(self): """Test fetch zip method.""" myUrl = 'http://osm.linfiniti.com/buildings-shp?' + \ 'bbox=20.389938354492188,-34.10782492987083' \ ',20.712661743164062,' + \ '-34.008273470938335&obj=building' myTempFilePath = tempfile.mktemp('shapefiles') self.importDlg.fetch_zip(myUrl, myTempFilePath) myMessage = "file %s not exist" % myTempFilePath assert os.path.exists(myTempFilePath), myMessage # cleanup os.remove(myTempFilePath) def test_extract_zip(self): """Test extract_zip method.""" myOutDir = tempfile.mkdtemp() myInput = os.path.abspath( os.path.join(TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) self.importDlg.extract_zip(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_download(self): """Test download method.""" 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.download() myResult = self.importDlg.progressDialog.result() myMessage = "result do not match. current result is %s " % myResult assert myResult == QDialog.Accepted, myMessage def test_load_shapefile(self): """Test loading shape file to QGIS Main Window """ myInput = os.path.abspath( os.path.join(TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) myOutDir = tempfile.mkdtemp() self.importDlg.extract_zip(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.load_shapefile() #FIXME(gigih): need to check if layer is loaded to QGIS # remove temporary folder and all of its content shutil.rmtree(myOutDir)
class ImportDialogTest(unittest.TestCase): """Test Import Dialog widget """ def setUp(self): """Runs before each test.""" self.dialog = OsmDownloader(PARENT, IFACE) ## provide Fake QNetworkAccessManager for self.network_manager self.dialog.network_manager = FakeQNetworkAccessManager() #noinspection PyMethodMayBeStatic def test_download_url(self): """Test we can download a zip. Uses a mock network stack.""" manager = 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). # ...or not...changed on 5 Dec 2013 by Tim to hash below... unique_hash = 'd4b691cd9d99117b2ea34586d3e7eeb8' url = 'http://google.com' path = tempfile.mktemp() download_url(manager, url, path) assert_hash_for_file(unique_hash, path) def test_fetch_zip(self): """Test fetch zip method.""" url = ('http://osm.linfiniti.com/buildings-shp?' 'bbox=20.389938354492188,-34.10782492987083' ',20.712661743164062,' '-34.008273470938335&obj=building') path = tempfile.mktemp('shapefiles') self.dialog.fetch_zip(url, path) message = "file %s not exist" % path assert os.path.exists(path), message # cleanup os.remove(path) def test_extract_zip(self): """Test extract_zip method.""" base_path = tempfile.mkdtemp() zipfile = os.path.abspath( os.path.join(TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) self.dialog.extract_zip(zipfile, base_path) message = "file {0} not exist" file_name = 'planet_osm_line.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) file_name = 'planet_osm_point.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) file_name = 'planet_osm_polygon.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) # remove temporary folder and all of its content shutil.rmtree(base_path) def test_download(self): """Test download method.""" output_directory = tempfile.mkdtemp() self.dialog.output_directory.setText(output_directory) self.dialog.min_longitude.setText('20.389938354492188') self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_longitude.setText('20.712661743164062') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.download('buildings') result = self.dialog.progress_dialog.result() message = "result do not match. current result is %s " % result assert result == QDialog.Accepted, message def test_load_shapefile(self): """Test loading shape file to QGIS Main Window """ zip_path = os.path.abspath( os.path.join(TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) output_path = tempfile.mkdtemp() self.dialog.extract_zip(zip_path, output_path) # outDir must be set to output_path because loadShapeFile() use # that variable to determine the location of shape files. self.dialog.output_directory.setText(output_path) self.dialog.load_shapefile('buildings') shutil.rmtree(output_path)
class ImportDialogTest(unittest.TestCase): """Test Import Dialog widget """ #noinspection PyPep8Naming def setUp(self): """Runs before each test.""" self.dialog = OsmDownloader(PARENT, IFACE) ## provide Fake QNetworkAccessManager for self.network_manager self.dialog.network_manager = FakeQNetworkAccessManager() def test_validate_extent(self): """Test validate extent method.""" # Normal case self.dialog.min_longitude.setText('20.389938354492188') self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_longitude.setText('20.712661743164062') self.dialog.max_latitude.setText('-34.008273470938335') self.assertTrue(self.dialog.validate_extent()) # min_latitude >= max_latitude self.dialog.min_latitude.setText('34.10782492987083') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.min_longitude.setText('20.389938354492188') self.dialog.max_longitude.setText('20.712661743164062') self.assertFalse(self.dialog.validate_extent()) # min_longitude >= max_longitude self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.min_longitude.setText('34.10782492987083') self.dialog.max_longitude.setText('-34.008273470938335') self.assertFalse(self.dialog.validate_extent()) # min_latitude < -90 or > 90 self.dialog.min_latitude.setText('-134.10782492987083') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.min_longitude.setText('20.389938354492188') self.dialog.max_longitude.setText('20.712661743164062') self.assertFalse(self.dialog.validate_extent()) # max_latitude < -90 or > 90 self.dialog.min_latitude.setText('-9.10782492987083') self.dialog.max_latitude.setText('91.10782492987083') self.dialog.min_longitude.setText('20.389938354492188') self.dialog.max_longitude.setText('20.712661743164062') self.assertFalse(self.dialog.validate_extent()) # min_longitude < -180 or > 180 self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.min_longitude.setText('-184.10782492987083') self.dialog.max_longitude.setText('20.712661743164062') self.assertFalse(self.dialog.validate_extent()) # max_longitude < -180 or > 180 self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.min_longitude.setText('20.389938354492188') self.dialog.max_longitude.setText('180.712661743164062') self.assertFalse(self.dialog.validate_extent()) def test_fetch_zip(self): """Test fetch zip method.""" url = ( 'http://osm.linfiniti.com/buildings-shp?' 'bbox=20.389938354492188,-34.10782492987083' ',20.712661743164062,' '-34.008273470938335&obj=building') path = tempfile.mktemp('shapefiles') self.dialog.fetch_zip(url, path) message = "file %s not exist" % path assert os.path.exists(path), message # cleanup os.remove(path) def test_extract_zip(self): """Test extract_zip method.""" base_path = tempfile.mkdtemp() zipfile = os.path.abspath(os.path.join( TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) self.dialog.extract_zip(zipfile, base_path) message = "file {0} not exist" file_name = 'planet_osm_line.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) file_name = 'planet_osm_point.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) file_name = 'planet_osm_polygon.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) # remove temporary folder and all of its content shutil.rmtree(base_path) def test_download(self): """Test download method.""" output_directory = tempfile.mkdtemp() self.dialog.output_directory.setText(output_directory) self.dialog.min_longitude.setText('20.389938354492188') self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_longitude.setText('20.712661743164062') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.download('buildings') result = self.dialog.progress_dialog.result() message = "result do not match. current result is %s " % result assert result == QDialog.Accepted, message def test_load_shapefile(self): """Test loading shape file to QGIS Main Window """ zip_path = os.path.abspath(os.path.join( TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) output_path = tempfile.mkdtemp() self.dialog.extract_zip(zip_path, output_path) # outDir must be set to output_path because loadShapeFile() use # that variable to determine the location of shape files. self.dialog.output_directory.setText(output_path) self.dialog.load_shapefile('buildings') shutil.rmtree(output_path)
class ImportDialogTest(unittest.TestCase): """Test Import Dialog widget """ def setUp(self): """Runs before each test.""" self.dialog = OsmDownloader(PARENT, IFACE) ## provide Fake QNetworkAccessManager for self.network_manager self.dialog.network_manager = FakeQNetworkAccessManager() #noinspection PyMethodMayBeStatic def test_download_url(self): """Test we can download a zip. Uses a mock network stack.""" manager = 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). # ...or not...changed on 5 Dec 2013 by Tim to hash below... unique_hash = 'd4b691cd9d99117b2ea34586d3e7eeb8' url = 'http://google.com' path = tempfile.mktemp() download_url(manager, url, path) assert_hash_for_file(unique_hash, path) def test_fetch_zip(self): """Test fetch zip method.""" url = ( 'http://osm.linfiniti.com/buildings-shp?' 'bbox=20.389938354492188,-34.10782492987083' ',20.712661743164062,' '-34.008273470938335&obj=building') path = tempfile.mktemp('shapefiles') self.dialog.fetch_zip(url, path) message = "file %s not exist" % path assert os.path.exists(path), message # cleanup os.remove(path) def test_extract_zip(self): """Test extract_zip method.""" base_path = tempfile.mkdtemp() zipfile = os.path.abspath(os.path.join( TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) self.dialog.extract_zip(zipfile, base_path) message = "file {0} not exist" file_name = 'planet_osm_line.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) file_name = 'planet_osm_point.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) file_name = 'planet_osm_polygon.shp' path = os.path.join(base_path, file_name) assert os.path.exists(path), message.format(file_name) # remove temporary folder and all of its content shutil.rmtree(base_path) def test_download(self): """Test download method.""" output_directory = tempfile.mkdtemp() self.dialog.output_directory.setText(output_directory) self.dialog.min_longitude.setText('20.389938354492188') self.dialog.min_latitude.setText('-34.10782492987083') self.dialog.max_longitude.setText('20.712661743164062') self.dialog.max_latitude.setText('-34.008273470938335') self.dialog.download('buildings') result = self.dialog.progress_dialog.result() message = "result do not match. current result is %s " % result assert result == QDialog.Accepted, message def test_load_shapefile(self): """Test loading shape file to QGIS Main Window """ zip_path = os.path.abspath(os.path.join( TEST_DATA_DIR, 'test-importdlg-extractzip.zip')) output_path = tempfile.mkdtemp() self.dialog.extract_zip(zip_path, output_path) # outDir must be set to output_path because loadShapeFile() use # that variable to determine the location of shape files. self.dialog.output_directory.setText(output_path) self.dialog.load_shapefile('buildings') shutil.rmtree(output_path)