class ImportDialogTest(unittest.TestCase): """Test Import Dialog widget """ # noinspection PyPep8Naming def setUp(self): """Runs before each test.""" self.dialog = OsmDownloaderDialog(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() zip_file_path = test_data_path('control', 'files', 'test-importdlg-extractzip.zip') self.dialog.extract_zip(zip_file_path, 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_file_path = test_data_path('control', 'files', 'test-importdlg-extractzip.zip') output_path = tempfile.mkdtemp() self.dialog.extract_zip(zip_file_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 = OsmDownloaderDialog(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() zip_file_path = test_data_path( 'control', 'files', 'test-importdlg-extractzip.zip') self.dialog.extract_zip(zip_file_path, 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_file_path = test_data_path( 'control', 'files', 'test-importdlg-extractzip.zip') output_path = tempfile.mkdtemp() self.dialog.extract_zip(zip_file_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 = OsmDownloaderDialog(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.""" feature = 'buildings' url = ( 'http://osm.linfiniti.com/buildings-shp?' 'bbox=20.389938354492188,-34.10782492987083' ',20.712661743164062,' '-34.008273470938335&obj=%s' % feature) path = tempfile.mktemp('shapefiles') self.dialog.fetch_zip(url, path, feature) message = "file %s not exist" % path assert os.path.exists(path), message # cleanup os.remove(path) def test_suffix_extracting_shapefile(self): """Test existing files method.""" path = tempfile.mkdtemp('existing-files') # Create some files one_file = os.path.join(path, 'a.txt') open(one_file, 'a').close() other_file = os.path.join(path, 'a-1.txt') open(other_file, 'a').close() message = "Index for existing files is wrong." result = self.dialog.get_unique_file_path_suffix(one_file) assert result == 2, message os.remove(other_file) result = self.dialog.get_unique_file_path_suffix(one_file) assert result == 1, message os.remove(one_file) result = self.dialog.get_unique_file_path_suffix(one_file) assert result == 0, message # cleanup shutil.rmtree(path) def test_extract_zip(self): """Test extract_zip method which will only take care of one file for each extensions. If many files has the same extension, only the last one will be copied. """ base_path = tempfile.mkdtemp() base_file_path = os.path.join(base_path, 'test') zip_file_path = test_data_path( 'control', 'files', 'test-importdlg-extractzip.zip') self.dialog.extract_zip(zip_file_path, base_file_path) message = "file {0} not exist" path = '%s.shp' % base_file_path assert os.path.exists(path), message.format(path) # 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', output_directory) 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_file_path = test_data_path( 'control', 'files', 'test-importdlg-extractzip.zip') output_path = tempfile.mkdtemp() self.dialog.extract_zip(zip_file_path, output_path) self.dialog.load_shapefile('buildings', output_path) shutil.rmtree(output_path)