Skip to content

Commit

Permalink
lint: run linter with line-length change 99 --> 100
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Jan 9, 2024
1 parent b7527fc commit 05738bd
Show file tree
Hide file tree
Showing 30 changed files with 51 additions and 150 deletions.
4 changes: 1 addition & 3 deletions backend/geonature/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,7 @@ def configure_alembic(alembic_config):
'migrations' entry point value of the 'gn_module' group for all modules having such entry point.
Thus, alembic will find migrations of all installed geonature modules.
"""
version_locations = set(
alembic_config.get_main_option("version_locations", default="").split()
)
version_locations = set(alembic_config.get_main_option("version_locations", default="").split())
if "VERSION_LOCATIONS" in config["ALEMBIC"]:
version_locations |= set(config["ALEMBIC"]["VERSION_LOCATIONS"].split())
for entry_point in chain(
Expand Down
6 changes: 2 additions & 4 deletions backend/geonature/core/command/create_gn_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ def install_gn_module(x_arg, module_path, module_code, build, upgrade_db):
click.echo("Installation / mise à jour de la base de données…")
if not module_db_upgrade(module_dist, x_arg=x_arg):
click.echo(
"Le module est déjà déclaré en base. "
"Installation de la base de données ignorée."
"Le module est déjà déclaré en base. " "Installation de la base de données ignorée."
)


Expand Down Expand Up @@ -137,6 +136,5 @@ def upgrade_modules_db(directory, sql, tag, x_arg, module_codes):
click.echo(f"Mise-à-jour du module {module_code}…")
if not module_db_upgrade(module_dist, directory, sql, tag, x_arg):
click.echo(
"Le module est déjà déclaré en base. "
"Installation de la base de données ignorée."
"Le module est déjà déclaré en base. " "Installation de la base de données ignorée."
)
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_commons/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,7 @@ def _persist_media_db(self):
if "check_entity_field_exist" in exp.args[0]:
raise Exception("{} doesn't exists".format(self.data["id_table_location"]))
if "fk_t_medias_check_entity_value" in exp.args[0]:
raise Exception(
"id {} of {} doesn't exists".format(self.data["id_table_location"])
)
raise Exception("id {} of {} doesn't exists".format(self.data["id_table_location"]))
else:
raise Exception("Errors {}".format(exp.args))

Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_commons/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,9 +231,7 @@ def get_t_mobile_apps():
app_dict["url_apk"] = url_for("media", filename=str(relative_apk_path), _external=True)

relative_settings_path = Path(f"mobile/{app.app_code.lower()}/settings.json")
app_dict["url_settings"] = url_for(
"media", filename=relative_settings_path, _external=True
)
app_dict["url_settings"] = url_for("media", filename=relative_settings_path, _external=True)
settings_file = Path(current_app.config["MEDIA_FOLDER"]) / relative_settings_path
with settings_file.open() as f:
app_dict["settings"] = json.load(f)
Expand Down
8 changes: 2 additions & 6 deletions backend/geonature/core/gn_meta/models/aframework.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,7 @@ def filter_by_params(cls, params={}, *, _ds_search=True, query=None):
if name
else True
)
.where(
TAcquisitionFramework.acquisition_framework_start_date == date if date else True
)
.where(TAcquisitionFramework.acquisition_framework_start_date == date if date else True)
)

actors = []
Expand Down Expand Up @@ -326,9 +324,7 @@ def filter_by_params(cls, params={}, *, _ds_search=True, query=None):
if _ds_search:
ors.append(
TAcquisitionFramework.datasets.any(
TDatasets.filter_by_params(
{"search": search}, _af_search=False
).whereclause
TDatasets.filter_by_params({"search": search}, _af_search=False).whereclause
),
)
query = query.where(sa.or_(*ors))
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_meta/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,7 @@ def get_metadata_list(role, scope, args, exclude_cols):
if acquisition_framework_name
else True
)
.where(
CorAcquisitionFrameworkActor.id_organism == id_organism if id_organism else True
)
.where(CorAcquisitionFrameworkActor.id_organism == id_organism if id_organism else True)
.where(CorAcquisitionFrameworkActor.id_role == id_role if id_role else True)
)

Expand Down
8 changes: 2 additions & 6 deletions backend/geonature/core/gn_meta/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,9 +887,7 @@ def get_acquisition_framework_stats(id_acquisition_framework):
nb_observations = db.session.execute(
select(func.count("*"))
.select_from(Synthese)
.where(
Synthese.dataset.has(TDatasets.id_acquisition_framework == id_acquisition_framework)
)
.where(Synthese.dataset.has(TDatasets.id_acquisition_framework == id_acquisition_framework))
).scalar_one()

nb_habitats = 0
Expand Down Expand Up @@ -966,9 +964,7 @@ def publish_acquisition_framework_mail(af):
)

# Mail subject
mail_subject = (
"Dépôt du cadre d'acquisition " + str(af.unique_acquisition_framework_id).upper()
)
mail_subject = "Dépôt du cadre d'acquisition " + str(af.unique_acquisition_framework_id).upper()
mail_subject_base = current_app.config["METADATA"]["MAIL_SUBJECT_AF_CLOSED_BASE"]
if mail_subject_base:
mail_subject = mail_subject_base + " " + mail_subject
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_permissions/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,7 @@ def permissions_formatter(view, context, model, name):
for ap in available_permissions:
own_permissions = list(
filter(
lambda p: p.module == ap.module
and p.object == ap.object
and p.action == ap.action,
lambda p: p.module == ap.module and p.object == ap.object and p.action == ap.action,
model.permissions,
)
)
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_profiles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class VSyntheseForProfiles(db.Model):
nomenclature_life_stage = db.relationship(
TNomenclatures, foreign_keys=[id_nomenclature_life_stage]
)
id_nomenclature_valid_status = db.Column(
db.Integer, ForeignKey(TNomenclatures.id_nomenclature)
)
id_nomenclature_valid_status = db.Column(db.Integer, ForeignKey(TNomenclatures.id_nomenclature))
nomenclature_valid_status = db.relationship(
TNomenclatures, foreign_keys=[id_nomenclature_valid_status]
)
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_synthese/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,9 +359,7 @@ class Synthese(DB.Model):
id_nomenclature_blurring = db.Column(
db.Integer, ForeignKey(TNomenclatures.id_nomenclature), server_default=FetchedValue()
)
nomenclature_blurring = db.relationship(
TNomenclatures, foreign_keys=[id_nomenclature_blurring]
)
nomenclature_blurring = db.relationship(TNomenclatures, foreign_keys=[id_nomenclature_blurring])
id_nomenclature_source_status = db.Column(
db.Integer, ForeignKey(TNomenclatures.id_nomenclature), server_default=FetchedValue()
)
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/gn_synthese/utils/blurring.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def build_blurred_precise_geom_queries(
)
# Joins here are needed to retrieve the blurred geometry
blurred_geom_query.add_join(LAreasAlias, LAreasAlias.id_area, CorAreaSyntheseAlias.id_area)
blurred_geom_query.add_join(
BibAreasTypesAlias, BibAreasTypesAlias.id_type, LAreasAlias.id_type
)
blurred_geom_query.add_join(BibAreasTypesAlias, BibAreasTypesAlias.id_type, LAreasAlias.id_type)
blurred_geom_query.add_join(
cor_sensitivity_area_type,
cor_sensitivity_area_type.c.id_area_type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,7 @@ def filter_other_filters(self, user):
comment_filter = ~comment_filter
self.query = self.query.where(comment_filter)
if "id_dataset" in self.filters:
self.query = self.query.where(
self.model.id_dataset.in_(self.filters.pop("id_dataset"))
)
self.query = self.query.where(self.model.id_dataset.in_(self.filters.pop("id_dataset")))
if "observers" in self.filters:
# découpe des éléments saisies par des ","
observers = self.filters.pop("observers").split(",")
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/notifications/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,7 @@ def count_notification():
notificationNumber = db.session.execute(
select(func.count("*"))
.select_from(Notification)
.where(
Notification.id_role == g.current_user.id_role, Notification.code_status == "UNREAD"
)
.where(Notification.id_role == g.current_user.id_role, Notification.code_status == "UNREAD")
).scalar_one()
return jsonify(notificationNumber)

Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/core/users/register_post_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ def validate_temp_user(data):
"""
token = data.get("token", None)

user = DB.session.scalars(
select(TempUser).where(TempUser.token_role == token).limit(1)
).first()
user = DB.session.scalars(select(TempUser).where(TempUser.token_role == token).limit(1)).first()
if not user:
return {
"msg": "{token}: ce token n'est pas associé à un compte temporaire".format(token=token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -638,8 +638,6 @@ def downgrade():
drop 'backup_t_filters' after 'backup_cor_role_action_filter_module_object' because of
'fk_backup_cor_r_a_f_m_o_id_filter' referencing 'backup_t_filters'
"""
op.drop_table(
schema="gn_permissions", table_name="backup_cor_role_action_filter_module_object"
)
op.drop_table(schema="gn_permissions", table_name="backup_cor_role_action_filter_module_object")
op.drop_table(schema="gn_permissions", table_name="backup_t_filters")
op.drop_table(schema="gn_permissions", table_name="backup_bib_filters_type")
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,7 @@ def upgrade():
ForeignKey(SCHEMA_NAME + ".bib_notifications_categories.code"),
nullable=False,
),
UniqueConstraint(
"id_role", "code_method", "code_category", name="un_role_method_category"
),
UniqueConstraint("id_role", "code_method", "code_category", name="un_role_method_category"),
schema=SCHEMA_NAME,
)

Expand Down
24 changes: 6 additions & 18 deletions backend/geonature/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ def test_install_gn_module_dist_code_is_GEONATURE(self, monkeypatch):
def test_install_gn_module_no_module_code(self, monkeypatch):
patch_monkeypatch(monkeypatch)
module_path = "backend/geonature/core"
monkeypatch.setattr(
install_module, "iter_modules_dist", iter_module_dist_mock("geonature")
)
monkeypatch.setattr(install_module, "iter_modules_dist", iter_module_dist_mock("geonature"))
result = self.cli.invoke(install_module.install_gn_module, [module_path])
assert result.exit_code == 0

Expand All @@ -147,25 +145,19 @@ def test_install_gn_module_empty_iter_module_dist(self, monkeypatch):
monkeypatch.setattr(install_module, "iter_modules_dist", lambda: [])
result = self.cli.invoke(install_module.install_gn_module, [module_path])
assert result.exit_code > 0
monkeypatch.setattr(
install_module, "iter_modules_dist", iter_module_dist_mock("geonature")
)
monkeypatch.setattr(install_module, "iter_modules_dist", iter_module_dist_mock("geonature"))

def test_install_gn_module_nomodule_code(self, monkeypatch):
patch_monkeypatch(monkeypatch)
module_path = "backend/geonature/core"
monkeypatch.setattr(
install_module, "iter_modules_dist", iter_module_dist_mock("geonature")
)
monkeypatch.setattr(install_module, "iter_modules_dist", iter_module_dist_mock("geonature"))
result = self.cli.invoke(install_module.install_gn_module, [module_path, "--build=false"])
assert result.exit_code == 0

def test_install_gn_module_false_upgrade_db(self, monkeypatch):
patch_monkeypatch(monkeypatch)
module_path = "backend/geonature/core"
monkeypatch.setattr(
install_module, "iter_modules_dist", iter_module_dist_mock("geonature")
)
monkeypatch.setattr(install_module, "iter_modules_dist", iter_module_dist_mock("geonature"))

result = self.cli.invoke(
install_module.install_gn_module, [module_path, "--upgrade-db=false"]
Expand All @@ -175,9 +167,7 @@ def test_install_gn_module_false_upgrade_db(self, monkeypatch):
def test_install_gn_module_symlink_not_exists(self, monkeypatch):
patch_monkeypatch(monkeypatch)
module_path = "backend/geonature/core"
monkeypatch.setattr(
install_module, "iter_modules_dist", iter_module_dist_mock("geonature")
)
monkeypatch.setattr(install_module, "iter_modules_dist", iter_module_dist_mock("geonature"))
monkeypatch.setattr(install_module.os.path, "exists", lambda x: False)
result = self.cli.invoke(install_module.install_gn_module, [module_path])

Expand All @@ -192,9 +182,7 @@ def test_install_gn_module_module_notin_sysmodule(self, monkeypatch):
assert result.exit_code > 0 # will fail

def test_upgrade_modules_db(self, monkeypatch):
monkeypatch.setattr(
install_module, "iter_modules_dist", iter_module_dist_mock("geonature")
)
monkeypatch.setattr(install_module, "iter_modules_dist", iter_module_dist_mock("geonature"))
result = self.cli.invoke(install_module.upgrade_modules_db, [])
assert result.exit_code > 0

Expand Down
8 changes: 2 additions & 6 deletions backend/geonature/tests/test_gn_commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def additional_field(app, datasets):
module = db.session.execute(
select(TModules).where(TModules.module_code == "SYNTHESE")
).scalar_one()
obj = db.session.execute(
select(PermObject).where(PermObject.code_object == "ALL")
).scalar_one()
obj = db.session.execute(select(PermObject).where(PermObject.code_object == "ALL")).scalar_one()
datasets = list(datasets.values())
additional_field = TAdditionalFields(
field_name="test",
Expand Down Expand Up @@ -454,9 +452,7 @@ def test_add_place(self, users):
assert response.status_code == 200
assert db.session.scalar(
exists()
.where(
TPlaces.place_name == place.place_name, TPlaces.id_role == users["user"].id_role
)
.where(TPlaces.place_name == place.place_name, TPlaces.id_role == users["user"].id_role)
.select()
)

Expand Down
16 changes: 4 additions & 12 deletions backend/geonature/tests/test_gn_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,7 @@ def get_csv_from_response(data):

@pytest.mark.usefixtures("client_class", "temporary_transaction")
class TestGNMeta:
def test_acquisition_frameworks_permissions(
self, app, acquisition_frameworks, datasets, users
):
def test_acquisition_frameworks_permissions(self, app, acquisition_frameworks, datasets, users):
af = acquisition_frameworks["own_af"]
with app.test_request_context(headers=logged_user_headers(users["user"])):
app.preprocess_request()
Expand Down Expand Up @@ -478,9 +476,7 @@ def test_get_export_pdf_acquisition_frameworks(self, users, acquisition_framewor
set_logged_user(self.client, users["user"])

response = self.client.post(
url_for(
"gn_meta.get_export_pdf_acquisition_frameworks", id_acquisition_framework=af_id
)
url_for("gn_meta.get_export_pdf_acquisition_frameworks", id_acquisition_framework=af_id)
)

assert response.status_code == 200
Expand All @@ -489,9 +485,7 @@ def test_get_export_pdf_acquisition_frameworks_unauthorized(self, acquisition_fr
af_id = acquisition_frameworks["own_af"].id_acquisition_framework

response = self.client.post(
url_for(
"gn_meta.get_export_pdf_acquisition_frameworks", id_acquisition_framework=af_id
)
url_for("gn_meta.get_export_pdf_acquisition_frameworks", id_acquisition_framework=af_id)
)

assert response.status_code == Unauthorized.code
Expand Down Expand Up @@ -1043,9 +1037,7 @@ def test__get_create_scope(self, app, users):
create = TDatasets._get_create_scope(module_code=modcode)

usercreate = TDatasets._get_create_scope(module_code=modcode, user=users["user"])
norightcreate = TDatasets._get_create_scope(
module_code=modcode, user=users["noright_user"]
)
norightcreate = TDatasets._get_create_scope(module_code=modcode, user=users["noright_user"])
associatecreate = TDatasets._get_create_scope(
module_code=modcode, user=users["associate_user"]
)
Expand Down
8 changes: 2 additions & 6 deletions backend/geonature/tests/test_gn_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,7 @@ def test_checks_all_false(

def test_get_phenology(self, sample_synthese_records_for_profile):
response = self.client.get(
url_for(
"gn_profiles.get_phenology", cd_ref=sample_synthese_records_for_profile.cd_nom
),
url_for("gn_profiles.get_phenology", cd_ref=sample_synthese_records_for_profile.cd_nom),
query_string={
"id_nomenclature_life_stage": db.session.scalar(
sa.select(func.ref_nomenclatures.get_id_nomenclature("STADE_VIE", "10"))
Expand Down Expand Up @@ -344,9 +342,7 @@ def test_get_observation_score_no_altitude(self, sample_synthese_records_for_pro
assert response.status_code == 400, response.json
assert response.json["description"] == "Missing altitude_min or altitude_max"

def test_get_observation_score_not_observed_altitude(
self, sample_synthese_records_for_profile
):
def test_get_observation_score_not_observed_altitude(self, sample_synthese_records_for_profile):
alt_min = 500
alt_max = 600
data = {
Expand Down
16 changes: 4 additions & 12 deletions backend/geonature/tests/test_notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,27 +167,19 @@ def test_count_notification(self, users, notification_data):
def test_update_notification(self, users, notification_data):
# Init data for test
url = "notifications.update_notification"
log.debug(
"Url d'appel %s", url_for(url, id_notification=notification_data.id_notification)
)
log.debug("Url d'appel %s", url_for(url, id_notification=notification_data.id_notification))

response = self.client.post(
url_for(url, id_notification=notification_data.id_notification)
)
response = self.client.post(url_for(url, id_notification=notification_data.id_notification))
assert response.status_code == Unauthorized.code

# TEST CONNECTED USER BUT NOTIFICATION DOES NOT EXIST FOR THIS USER
set_logged_user(self.client, users["user"])
response = self.client.post(
url_for(url, id_notification=notification_data.id_notification)
)
response = self.client.post(url_for(url, id_notification=notification_data.id_notification))
assert response.status_code == Forbidden.code

# TEST CONNECTED USER WITH NOTIFICATION
set_logged_user(self.client, users["admin_user"])
response = self.client.post(
url_for(url, id_notification=notification_data.id_notification)
)
response = self.client.post(url_for(url, id_notification=notification_data.id_notification))
assert response.status_code == 200

def test_delete_all_notifications(self, users, notification_data):
Expand Down
4 changes: 1 addition & 3 deletions backend/geonature/tests/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,7 @@ def _permissions(role, cruved, *, module=module_gn, **kwargs):
else:
s = int(s)
db.session.add(
Permission(
role=role, action=actions[a], module=module, scope_value=s, **kwargs
)
Permission(role=role, action=actions[a], module=module, scope_value=s, **kwargs)
)

return _permissions
Expand Down
Loading

0 comments on commit 05738bd

Please sign in to comment.