def test_translation(self): """Test for metadata translation.""" from safe_qgis.tools.wizard_dialog import WizardDialog from safe_qgis.utilities.utilities_for_testing import ( clone_shp_layer, remove_temp_file) from safe_qgis.safe_interface import BOUNDDATA from safe.common.testing import get_qgis_app # Get QGis app handle # noinspection PyPep8Naming _, _, IFACE, PARENT = get_qgis_app() layer = clone_shp_layer( name='kabupaten_jakarta', include_keywords=True, directory=BOUNDDATA) # noinspection PyTypeChecker dialog = WizardDialog(PARENT, IFACE, None, layer) expected_categories = ['keterpaparan', 'ancaman', 'agregasi'] # noinspection PyTypeChecker self.check_list(expected_categories, dialog.lstCategories) self.check_current_text('agregasi', dialog.lstCategories) dialog.pbnNext.click() remove_temp_file(layer.source())
__author__ = '*****@*****.**' __revision__ = 'cb2a47cca51c54019ce7d93e6dc6c9f732b434b8' __date__ = '16/03/2014' __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 'Disaster Reduction') import unittest import tempfile #noinspection PyPackageRequirements from PyQt4.QtNetwork import QNetworkAccessManager from safe.common.testing import get_qgis_app # In our tests, we need to have this line below before importing any other # safe_qgis.__init__ to load all the configurations that we make for testing QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app() from safe_qgis.utilities.file_downloader import FileDownloader from safe_qgis.utilities.utilities_for_testing import assert_hash_for_file from safe_qgis.exceptions import DownloadError class FileDownloaderTest(unittest.TestCase): """Test FileDownloader class.""" #noinspection PyMethodMayBeStatic def test_download(self): """Test download.""" manager = QNetworkAccessManager(PARENT) # NOTE(gigih): # this is the hash of google front page.
def test_existing_complex_keywords(self): """Test for existing complex keywords in wizard in locale mode.""" from safe_qgis.tools.wizard_dialog import WizardDialog from safe_qgis.utilities.utilities_for_testing import ( clone_shp_layer, remove_temp_file) layer = clone_shp_layer(include_keywords=True) from safe.common.testing import get_qgis_app # Get QGis app handle # noinspection PyPep8Naming _, _, IFACE, PARENT = get_qgis_app() # noinspection PyTypeChecker dialog = WizardDialog(PARENT, IFACE, None, layer) # select hazard self.select_from_list_widget('ancaman', dialog.lstCategories) dialog.pbnNext.click() # select volcano self.select_from_list_widget('gunung berapi', dialog.lstSubcategories) dialog.pbnNext.click() # select volcano categorical unit self.select_from_list_widget('Kategori gunung berapi', dialog.lstUnits) dialog.pbnNext.click() # select GRIDCODE self.select_from_list_widget('GRIDCODE', dialog.lstFields) dialog.pbnNext.click() unit = dialog.selected_unit() default_classes = unit['classes'] unassigned_values = [] # no need to check actually, not save in file assigned_values = { 'low': ['5.0'], 'medium': ['3.0', '4.0'], 'high': ['2.0'] } dialog.populate_classified_values( unassigned_values, assigned_values, default_classes) dialog.pbnNext.click() source = 'Source' source_scale = 'Source Scale' source_url = 'Source Url' source_date = 'Source Date' dialog.leSource.setText(source) dialog.leSource_scale.setText(source_scale) dialog.leSource_url.setText(source_url) dialog.leSource_date.setText(source_date) dialog.pbnNext.click() # next dialog.pbnNext.click() # finish # noinspection PyTypeChecker dialog = WizardDialog(PARENT, IFACE, None, layer) # step 1 of 7 - select category self.check_current_text('ancaman', dialog.lstCategories) # Click Next dialog.pbnNext.click() # step 2 of 7 - select subcategory # noinspection PyTypeChecker self.check_current_text('gunung berapi', dialog.lstSubcategories) # Click Next dialog.pbnNext.click() # step 3 of 7 - select volcano units self.check_current_text('Kategori gunung berapi', dialog.lstUnits) # Click Next dialog.pbnNext.click() # step 4 of 7 - select field self.check_current_text('GRIDCODE', dialog.lstFields) # Click Next dialog.pbnNext.click() for index in range(dialog.lstUniqueValues.count()): message = ('%s Should be in unassigned values' % dialog.lstUniqueValues.item(index).text()) self.assertIn( dialog.lstUniqueValues.item(index).text(), unassigned_values, message) real_assigned_values = dialog.selected_mapping() self.assertDictEqual(real_assigned_values, assigned_values) # Click Next dialog.pbnNext.click() # step 6 of 7 - enter source message = ('Invalid Next button state in step 6! Disabled while ' 'source is optional') self.assertTrue(dialog.pbnNext.isEnabled(), message) message = 'Source should be %s' % source self.assertEqual(dialog.leSource.text(), source, message) message = 'Source Url should be %s' % source_url self.assertEqual(dialog.leSource_url.text(), source_url, message) message = 'Source Date should be %s' % source_date self.assertEqual(dialog.leSource_date.text(), source_date, message) message = 'Source Scale should be %s' % source_scale self.assertEqual(dialog.leSource_scale.text(), source_scale, message) dialog.pbnNext.click() dialog.pbnCancel.click() remove_temp_file(layer.source())
from safe.common.testing import get_qgis_app __author__ = '*****@*****.**' __date__ = '20/01/2011' __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 'Disaster Reduction') import os import unittest from qgis.core import ( QgsProviderRegistry, QgsCoordinateReferenceSystem, QgsRasterLayer) from safe_qgis.safe_interface import EXPDATA QGIS_APP = get_qgis_app() class QGISTest(unittest.TestCase): """Test the QGIS Environment""" def test_QGISEnvironment(self): """QGIS environment has the expected providers""" r = QgsProviderRegistry.instance() #for item in r.providerList(): # print str(item) #print 'Provider count: %s' % len(r.providerList()) assert 'gdal' in r.providerList() assert 'ogr' in r.providerList()
__author__ = '*****@*****.**' __date__ = '21/02/2011' __copyright__ = ('Copyright 2012, Australia Indonesia Facility for ' 'Disaster Reduction') # this import required to enable PyQt API v2 - DO NOT REMOVE! #noinspection PyUnresolvedReferences import qgis # pylint: disable=W0611 import unittest from safe.common.testing import get_qgis_app # Needed though not used below from safe_qgis.utilities.help import _show_local_help from safe_qgis.exceptions import HelpFileMissingError QGIS_APP, CANVAS, IFACE, PARENT = get_qgis_app() class HelpTest(unittest.TestCase): """Test that context help works.""" def test_local_help(self): """Test local help returns an error if the file is not found.""" # TODO this test is largely meaningless - try to come up with a # better approach... self.assertRaises(HelpFileMissingError, _show_local_help, context='idontexist') def test_local_help_better(self): """Test local help returns no error if the file is not found."""
def test_existing_complex_keywords(self): """Test for existing complex keywords in wizard in locale mode.""" from safe_qgis.tools.wizard_dialog import WizardDialog from safe_qgis.utilities.utilities_for_testing import ( clone_shp_layer, remove_vector_temp_file) layer = clone_shp_layer(include_keywords=True) from safe.common.testing import get_qgis_app # Get QGis app handle # noinspection PyPep8Naming _, _, IFACE, PARENT = get_qgis_app() # noinspection PyTypeChecker dialog = WizardDialog(PARENT, IFACE, None, layer) # select hazard self.select_from_list_widget('ancaman', dialog.lstCategories) dialog.pbnNext.click() # select volcano self.select_from_list_widget('gunung berapi', dialog.lstSubcategories) dialog.pbnNext.click() # select volcano categorical unit self.select_from_list_widget('Kategori gunung berapi', dialog.lstUnits) dialog.pbnNext.click() # select GRIDCODE self.select_from_list_widget('GRIDCODE', dialog.lstFields) dialog.pbnNext.click() unit = dialog.selected_unit() default_classes = unit['classes'] unassigned_values = [] # no need to check actually, not save in file assigned_values = { 'low': ['5.0'], 'medium': ['3.0', '4.0'], 'high': ['2.0'] } dialog.populate_classified_values( unassigned_values, assigned_values, default_classes) dialog.pbnNext.click() source = 'Source' source_scale = 'Source Scale' source_url = 'Source Url' source_date = 'Source Date' dialog.leSource.setText(source) dialog.leSource_scale.setText(source_scale) dialog.leSource_url.setText(source_url) dialog.leSource_date.setText(source_date) dialog.pbnNext.click() # next dialog.pbnNext.click() # finish # noinspection PyTypeChecker dialog = WizardDialog(PARENT, IFACE, None, layer) # step 1 of 7 - select category self.check_current_text('ancaman', dialog.lstCategories) # Click Next dialog.pbnNext.click() # step 2 of 7 - select subcategory # noinspection PyTypeChecker self.check_current_text('gunung berapi', dialog.lstSubcategories) # Click Next dialog.pbnNext.click() # step 3 of 7 - select volcano units self.check_current_text('Kategori gunung berapi', dialog.lstUnits) # Click Next dialog.pbnNext.click() # step 4 of 7 - select field self.check_current_text('GRIDCODE', dialog.lstFields) # Click Next dialog.pbnNext.click() for index in range(dialog.lstUniqueValues.count()): message = ('%s Should be in unassigned values' % dialog.lstUniqueValues.item(index).text()) self.assertIn( dialog.lstUniqueValues.item(index).text(), unassigned_values, message) real_assigned_values = dialog.selected_mapping() self.assertDictEqual(real_assigned_values, assigned_values) # Click Next dialog.pbnNext.click() # step 6 of 7 - enter source message = ('Invalid Next button state in step 6! Disabled while ' 'source is optional') self.assertTrue(dialog.pbnNext.isEnabled(), message) message = 'Source should be %s' % source self.assertEqual(dialog.leSource.text(), source, message) message = 'Source Url should be %s' % source_url self.assertEqual(dialog.leSource_url.text(), source_url, message) message = 'Source Date should be %s' % source_date self.assertEqual(dialog.leSource_date.text(), source_date, message) message = 'Source Scale should be %s' % source_scale self.assertEqual(dialog.leSource_scale.text(), source_scale, message) dialog.pbnNext.click() dialog.pbnCancel.click() remove_vector_temp_file(layer.source())