예제 #1
0
    def show_osm_downloader(self):
        """Show the OSM buildings downloader dialog."""
        from safe.gui.tools.osm_downloader_dialog import OsmDownloaderDialog

        dialog = OsmDownloaderDialog(self.iface.mainWindow(), self.iface)
        # otherwise dialog is never deleted
        dialog.setAttribute(Qt.WA_DeleteOnClose, True)
        dialog.show()  # non modal
예제 #2
0
class OsmDownloaderDialogTest(unittest.TestCase):
    """Test Osm Downloader Dialog widget

    .. versionchanged:: 3.2
    """

    # noinspection PyPep8Naming
    def setUp(self):
        """Runs before each test."""
        self.dialog = OsmDownloaderDialog(PARENT, IFACE)

    def test_checked_features(self):
        """Test checked features"""
        self.dialog.roads_flag.setChecked(False)
        self.dialog.buildings_flag.setChecked(False)
        self.dialog.building_points_flag.setChecked(False)
        self.dialog.flood_prone_flag.setChecked(False)
        self.dialog.evacuation_centers_flag.setChecked(False)
        self.dialog.boundary_flag.setChecked(False)
        expected = []
        get = self.dialog.get_checked_features()
        self.assertItemsEqual(expected, get)

        self.dialog.roads_flag.setChecked(True)
        self.dialog.buildings_flag.setChecked(True)
        self.dialog.building_points_flag.setChecked(True)
        self.dialog.flood_prone_flag.setChecked(False)
        self.dialog.evacuation_centers_flag.setChecked(True)
        self.dialog.boundary_flag.setChecked(False)
        expected = [
            'roads', 'buildings', 'building-points', 'evacuation-centers'
        ]
        get = self.dialog.get_checked_features()
        self.assertItemsEqual(expected, get)

        admin_level = 6
        self.dialog.admin_level_comboBox.setCurrentIndex(admin_level - 1)
        self.dialog.roads_flag.setChecked(False)
        self.dialog.buildings_flag.setChecked(True)
        self.dialog.building_points_flag.setChecked(True)
        self.dialog.flood_prone_flag.setChecked(True)
        self.dialog.evacuation_centers_flag.setChecked(True)
        self.dialog.boundary_flag.setChecked(True)
        expected = [
            'buildings', 'building-points', 'flood-prone',
            'evacuation-centers', 'boundary-6'
        ]
        get = self.dialog.get_checked_features()
        self.assertItemsEqual(expected, get)

    def test_detect_country(self):
        """Test if the country is well detected according to the extent."""
        # Extent in Zimbabwe.
        self.dialog.update_extent([29.4239, -18.2391, 29.4676, -18.2068])
        index = self.dialog.country_comboBox.currentIndex()
        country = self.dialog.country_comboBox.itemText(index)
        self.assertTrue(country == 'Zimbabwe')

        # Extent in Indonesia.
        self.dialog.update_extent([106.7741, -6.2609, 106.8874, -6.1859])
        index = self.dialog.country_comboBox.currentIndex()
        country = self.dialog.country_comboBox.itemText(index)
        self.assertTrue(country == 'Indonesia')

        # Extent in the middle of nowhere in the Indian Ocean, default value.
        self.dialog.update_extent([75.0586, -31.7477, 75.8867, -30.9022])
        index = self.dialog.country_comboBox.currentIndex()
        country = self.dialog.country_comboBox.itemText(index)
        self.assertTrue(country == 'Afghanistan')

    def test_populate_countries(self):
        """Test if items are in the combobox.
        For instance every admin_level from 1 to 11 and
        the first and last country (alphabetical order)."""
        self.assertTrue(self.dialog.admin_level_comboBox.count() == 11)
        self.assertTrue(
            self.dialog.country_comboBox.itemText(0) == 'Afghanistan')
        nb_items = self.dialog.country_comboBox.count()
        self.assertTrue(
            self.dialog.country_comboBox.itemText(nb_items - 1) == 'Zimbabwe')

    def test_admin_level_helper(self):
        """Test the helper by setting a country and an admin level."""
        admin_level = 8
        country = 'Indonesia'
        expected = 'which represents Community Group (Rukun Warga) in'

        self.dialog.admin_level_comboBox.setCurrentIndex(admin_level - 1)
        index = self.dialog.country_comboBox.findText(country)
        self.dialog.country_comboBox.setCurrentIndex(index)
        self.assertEquals(expected, self.dialog.boundary_helper.text())

        admin_level = 6
        country = 'Madagascar'
        expected = 'which represents Distrika (districts) in'

        self.dialog.admin_level_comboBox.setCurrentIndex(admin_level - 1)
        index = self.dialog.country_comboBox.findText(country)
        self.dialog.country_comboBox.setCurrentIndex(index)
        self.assertEquals(expected, self.dialog.boundary_helper.text())

    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)
예제 #3
0
 def setUp(self):
     """Runs before each test."""
     self.dialog = OsmDownloaderDialog(PARENT, IFACE)
예제 #4
0
    def setUp(self):
        """Runs before each test."""
        self.dialog = OsmDownloaderDialog(PARENT, IFACE)

        # provide Fake QNetworkAccessManager for self.network_manager
        self.dialog.network_manager = FakeQNetworkAccessManager()
예제 #5
0
파일: plugin.py 프로젝트: NyakudyaA/inasafe
    def show_osm_downloader(self):
        """Show the OSM buildings downloader dialog."""
        from safe.gui.tools.osm_downloader_dialog import OsmDownloaderDialog

        dialog = OsmDownloaderDialog(self.iface.mainWindow(), self.iface)
        dialog.show()  # non modal
예제 #6
0
    def show_osm_downloader(self):
        """Show the OSM buildings downloader dialog."""
        from safe.gui.tools.osm_downloader_dialog import OsmDownloaderDialog

        dialog = OsmDownloaderDialog(self.iface.mainWindow(), self.iface)
        dialog.exec_()  # modal
예제 #7
0
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)
예제 #8
0
    def setUp(self):
        """Runs before each test."""
        self.dialog = OsmDownloaderDialog(PARENT, IFACE)

        # provide Fake QNetworkAccessManager for self.network_manager
        self.dialog.network_manager = FakeQNetworkAccessManager()
예제 #9
0
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)
 def setUp(self):
     """Runs before each test."""
     self.dialog = OsmDownloaderDialog(PARENT, IFACE)
class OsmDownloaderDialogTest(unittest.TestCase):

    """Test Osm Downloader Dialog widget

    .. versionchanged:: 3.2
    """

    # noinspection PyPep8Naming
    def setUp(self):
        """Runs before each test."""
        self.dialog = OsmDownloaderDialog(PARENT, IFACE)

    def test_checked_features(self):
        """Test checked features"""
        self.dialog.roads_flag.setChecked(False)
        self.dialog.buildings_flag.setChecked(False)
        self.dialog.building_points_flag.setChecked(False)
        self.dialog.flood_prone_flag.setChecked(False)
        self.dialog.evacuation_centers_flag.setChecked(False)
        self.dialog.boundary_flag.setChecked(False)
        expected = []
        get = self.dialog.get_checked_features()
        self.assertItemsEqual(expected, get)

        self.dialog.roads_flag.setChecked(True)
        self.dialog.buildings_flag.setChecked(True)
        self.dialog.building_points_flag.setChecked(True)
        self.dialog.flood_prone_flag.setChecked(False)
        self.dialog.evacuation_centers_flag.setChecked(True)
        self.dialog.boundary_flag.setChecked(False)
        expected = [
            'roads',
            'buildings',
            'building-points',
            'evacuation-centers']
        get = self.dialog.get_checked_features()
        self.assertItemsEqual(expected, get)

        admin_level = 6
        self.dialog.admin_level_comboBox.setCurrentIndex(admin_level - 1)
        self.dialog.roads_flag.setChecked(False)
        self.dialog.buildings_flag.setChecked(True)
        self.dialog.building_points_flag.setChecked(True)
        self.dialog.flood_prone_flag.setChecked(True)
        self.dialog.evacuation_centers_flag.setChecked(True)
        self.dialog.boundary_flag.setChecked(True)
        expected = [
            'buildings',
            'building-points',
            'flood-prone',
            'evacuation-centers',
            'boundary-6']
        get = self.dialog.get_checked_features()
        self.assertItemsEqual(expected, get)

    def test_detect_country(self):
        """Test if the country is well detected according to the extent."""
        # Extent in Zimbabwe.
        self.dialog.update_extent([29.4239, -18.2391, 29.4676, -18.2068])
        index = self.dialog.country_comboBox.currentIndex()
        country = self.dialog.country_comboBox.itemText(index)
        self.assertTrue(country == 'Zimbabwe')

        # Extent in Indonesia.
        self.dialog.update_extent([106.7741, -6.2609, 106.8874, -6.1859])
        index = self.dialog.country_comboBox.currentIndex()
        country = self.dialog.country_comboBox.itemText(index)
        self.assertTrue(country == 'Indonesia')

        # Extent in the middle of nowhere in the Indian Ocean, default value.
        self.dialog.update_extent([75.0586, -31.7477, 75.8867, -30.9022])
        index = self.dialog.country_comboBox.currentIndex()
        country = self.dialog.country_comboBox.itemText(index)
        self.assertTrue(country == 'Afghanistan')

    def test_populate_countries(self):
        """Test if items are in the combobox.
        For instance every admin_level from 1 to 11 and
        the first and last country (alphabetical order)."""
        self.assertTrue(self.dialog.admin_level_comboBox.count() == 11)
        self.assertTrue(
            self.dialog.country_comboBox.itemText(0) == 'Afghanistan')
        nb_items = self.dialog.country_comboBox.count()
        self.assertTrue(
            self.dialog.country_comboBox.itemText(nb_items - 1) == 'Zimbabwe')

    def test_admin_level_helper(self):
        """Test the helper by setting a country and an admin level."""
        admin_level = 8
        country = 'Indonesia'
        expected = 'which represents Community Group (Rukun Warga) in'

        self.dialog.admin_level_comboBox.setCurrentIndex(admin_level - 1)
        index = self.dialog.country_comboBox.findText(country)
        self.dialog.country_comboBox.setCurrentIndex(index)
        self.assertEquals(expected, self.dialog.boundary_helper.text())

        admin_level = 6
        country = 'Madagascar'
        expected = 'which represents Distrika (districts) in'

        self.dialog.admin_level_comboBox.setCurrentIndex(admin_level - 1)
        index = self.dialog.country_comboBox.findText(country)
        self.dialog.country_comboBox.setCurrentIndex(index)
        self.assertEquals(expected, self.dialog.boundary_helper.text())

    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)
예제 #12
0
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)