Skip to content

Commit

Permalink
Ajout des imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Sep 4, 2023
1 parent 47b9e4e commit 6a58c00
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
25 changes: 6 additions & 19 deletions netads/processing_netads/data/import_impacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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}'"
Expand Down Expand Up @@ -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:
Expand Down
5 changes: 1 addition & 4 deletions netads/processing_netads/data/import_parcelles.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -131,7 +129,6 @@ def processAlgorithm(
)

if data_update:

feedback.pushInfo("## Mise à jour des données parcelles ##")

sql = f"""
Expand Down
12 changes: 6 additions & 6 deletions netads/tests/base_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
Expand All @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions netads/tests/test_load_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,25 @@


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()))
context = QgsProcessingContext()
context.setProject(project)

params = {
'CONNECTION_NAME': 'test_database',
'SCHEMA': 'netads',
"CONNECTION_NAME": "test_database",
"SCHEMA": "netads",
}
alg = "netads:load_layers"

with self.assertRaises(QgsProcessingException):
# 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,
Expand All @@ -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()

0 comments on commit 6a58c00

Please sign in to comment.