From 6a58c0069c0f170af7d08c27abf59e396470cb6c Mon Sep 17 00:00:00 2001 From: Etienne Trimaille Date: Mon, 4 Sep 2023 09:01:42 +0200 Subject: [PATCH] Ajout des imports --- .../processing_netads/data/import_impacts.py | 25 +++++-------------- .../data/import_parcelles.py | 5 +--- netads/tests/base_database.py | 12 ++++----- netads/tests/test_load_layers.py | 12 ++++----- 4 files changed, 19 insertions(+), 35 deletions(-) diff --git a/netads/processing_netads/data/import_impacts.py b/netads/processing_netads/data/import_impacts.py index 0b1fa0f..a993b5f 100644 --- a/netads/processing_netads/data/import_impacts.py +++ b/netads/processing_netads/data/import_impacts.py @@ -196,9 +196,7 @@ def processAlgorithm( connection_name = self.parameterAsConnectionName( parameters, self.CONNECTION_NAME, context ) - schema_netads = self.parameterAsSchema( - parameters, self.SCHEMA_NETADS, context - ) + schema_netads = self.parameterAsSchema(parameters, self.SCHEMA_NETADS, context) # noinspection PyArgumentList metadata = QgsProviderRegistry.instance().providerMetadata("postgres") @@ -253,9 +251,7 @@ def processAlgorithm( return {self.COUNT_FEATURES: 0, self.COUNT_NEW_IMPACTS: 0} crs = self.check_current_crs(connection, schema_netads, feedback) - feedback.pushInfo( - f"La projection du schéma {schema_netads} est en EPSG:{crs}." - ) + feedback.pushInfo(f"La projection du schéma {schema_netads} est en EPSG:{crs}.") layer = self.prepare_data( context, @@ -311,9 +307,7 @@ def processAlgorithm( return {self.COUNT_FEATURES: 0, self.COUNT_NEW_IMPACTS: 0} connection.executeSql("COMMIT;") - feedback.pushInfo( - f"{success} nouvelles géo-impacts dans la base de données" - ) + feedback.pushInfo(f"{success} nouvelles géo-impacts dans la base de données") return { self.COUNT_FEATURES: success, self.COUNT_NEW_IMPACTS: len(missing_in_db), @@ -512,9 +506,7 @@ def existing_impacts_in_database( uri.setTable("impacts") uri.setKeyColumn("id_impacts") existing_impacts = {} - existing_constraints_layer = QgsVectorLayer( - uri.uri(), "impacts", "postgres" - ) + existing_constraints_layer = QgsVectorLayer(uri.uri(), "impacts", "postgres") request = QgsFeatureRequest() request.setFilterExpression( f"\"groupe\" = '{group}' AND \"sous_groupe\" = '{sub_group}'" @@ -636,13 +628,8 @@ def unique_couple_input( uniques = [] uniques_str = [] for feature in layer.getFeatures(request): - - content_label = ImportImpactsAlg.clean_value( - feature.attribute(label_field) - ) - content_text = ImportImpactsAlg.clean_value( - feature.attribute(text_field) - ) + content_label = ImportImpactsAlg.clean_value(feature.attribute(label_field)) + content_text = ImportImpactsAlg.clean_value(feature.attribute(text_field)) couple = (content_label, content_text) if couple not in uniques: diff --git a/netads/processing_netads/data/import_parcelles.py b/netads/processing_netads/data/import_parcelles.py index 41c23e6..9628533 100644 --- a/netads/processing_netads/data/import_parcelles.py +++ b/netads/processing_netads/data/import_parcelles.py @@ -118,9 +118,7 @@ def processAlgorithm( schema_cadastre = self.parameterAsSchema( parameters, self.SCHEMA_CADASTRE, context ) - schema_netads = self.parameterAsSchema( - parameters, self.SCHEMA_NETADS, context - ) + schema_netads = self.parameterAsSchema(parameters, self.SCHEMA_NETADS, context) data_update = self.parameterAsBool(parameters, self.TRUNCATE_PARCELLES, context) @@ -131,7 +129,6 @@ def processAlgorithm( ) if data_update: - feedback.pushInfo("## Mise à jour des données parcelles ##") sql = f""" diff --git a/netads/tests/base_database.py b/netads/tests/base_database.py index a760fa3..3ba6ccf 100644 --- a/netads/tests/base_database.py +++ b/netads/tests/base_database.py @@ -7,9 +7,7 @@ QgsProviderRegistry, ) -from netads.processing_netads.provider import ( - NetAdsProvider as ProcessingProvider, -) +from netads.processing_netads.provider import NetAdsProvider as ProcessingProvider from netads.tests.base import BaseTestProcessing __copyright__ = "Copyright 2023, 3Liz" @@ -27,9 +25,9 @@ class DatabaseTestCase(BaseTestProcessing): def setUp(self) -> None: self.provider = None - self.metadata = QgsProviderRegistry.instance().providerMetadata('postgres') + self.metadata = QgsProviderRegistry.instance().providerMetadata("postgres") - self.connection = self.metadata.findConnection('test_database') + self.connection = self.metadata.findConnection("test_database") self.connection: QgsAbstractDatabaseProviderConnection if SCHEMA in self.connection.schemas(): self.connection.dropSchema(SCHEMA, True) @@ -46,7 +44,9 @@ def setUp(self) -> None: "CRS": "EPSG:2154", } processing.run( - "{}:create_database_structure".format(self.provider.id()), params, feedback=None, + "{}:create_database_structure".format(self.provider.id()), + params, + feedback=None, ) # def tearDown(self) -> None: diff --git a/netads/tests/test_load_layers.py b/netads/tests/test_load_layers.py index 52b452e..f8fb62a 100644 --- a/netads/tests/test_load_layers.py +++ b/netads/tests/test_load_layers.py @@ -12,9 +12,8 @@ class TestPlugin(DatabaseTestCase): - def test_import_layers(self): - """ Test import layers. """ + """Test import layers.""" project = QgsProject() variables = project.customVariables() self.assertNotIn("netads_idclient", list(variables.keys())) @@ -22,8 +21,8 @@ def test_import_layers(self): context.setProject(project) params = { - 'CONNECTION_NAME': 'test_database', - 'SCHEMA': 'netads', + "CONNECTION_NAME": "test_database", + "SCHEMA": "netads", } alg = "netads:load_layers" @@ -31,7 +30,7 @@ def test_import_layers(self): # Code client is not correct processing.run(alg, params, feedback=FeedbackPrint(), context=context) - params['CODE_CLIENT'] = 'test' + params["CODE_CLIENT"] = "test" results = processing.run( alg, @@ -43,9 +42,10 @@ def test_import_layers(self): variables = project.customVariables() self.assertEqual(variables["netads_idclient"], "test") - self.assertEqual(3, len(results['OUTPUT'])) + self.assertEqual(3, len(results["OUTPUT"])) if __name__ == "__main__": from qgis.testing import start_app + start_app()