Skip to content

Commit

Permalink
Feat(tests) apply lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Narcisi committed Aug 26, 2024
1 parent 779aa37 commit 59335b2
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 40 deletions.
4 changes: 1 addition & 3 deletions src/mtd_sync/mtd_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@
# config logger
logger.setLevel(configuration_mtd["SYNC_LOG_LEVEL"])
handler = logging.StreamHandler()
formatter = logging.Formatter(
"%(asctime)s | %(levelname)s : %(message)s", "%Y-%m-%d %H:%M:%S"
)
formatter = logging.Formatter("%(asctime)s | %(levelname)s : %(message)s", "%Y-%m-%d %H:%M:%S")
handler.setFormatter(formatter)
logger.addHandler(handler)
# avoid logging output dupplication
Expand Down
29 changes: 7 additions & 22 deletions src/mtd_sync/mtd_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ def sync_ds(ds, cd_nomenclatures):
af_uuid = ds.pop("uuid_acquisition_framework")
af = (
DB.session.execute(
select(TAcquisitionFramework).filter_by(
unique_acquisition_framework_id=af_uuid
)
select(TAcquisitionFramework).filter_by(unique_acquisition_framework_id=af_uuid)
)
.unique()
.scalar_one_or_none()
Expand All @@ -71,9 +69,7 @@ def sync_ds(ds, cd_nomenclatures):
ds["id_acquisition_framework"] = af.id_acquisition_framework
ds = {
field.replace("cd_nomenclature", "id_nomenclature"): (
func.ref_nomenclatures.get_id_nomenclature(
NOMENCLATURE_MAPPING[field], value
)
func.ref_nomenclatures.get_id_nomenclature(NOMENCLATURE_MAPPING[field], value)
if field.startswith("cd_nomenclature")
else value
)
Expand Down Expand Up @@ -128,9 +124,7 @@ def sync_af(af):
"""
af_uuid = af["unique_acquisition_framework_id"]
af_exists = DB.session.scalar(
exists()
.where(TAcquisitionFramework.unique_acquisition_framework_id == af_uuid)
.select()
exists().where(TAcquisitionFramework.unique_acquisition_framework_id == af_uuid).select()
)

# Update statement if AF already exists in DB else insert statement
Expand Down Expand Up @@ -163,9 +157,7 @@ def add_or_update_organism(uuid, nom, email):
:param email: org email
"""
# Test if actor already exists to avoid nextVal increase
org_exist = DB.session.scalar(
exists().where(BibOrganismes.uuid_organisme == uuid).select()
)
org_exist = DB.session.scalar(exists().where(BibOrganismes.uuid_organisme == uuid).select())

if org_exist:
statement = (
Expand Down Expand Up @@ -266,9 +258,7 @@ class CasAuthentificationError(GeonatureApiError):
def insert_user_and_org(info_user, update_user_organism: bool = True):
id_provider_inpn = current_app.config["MTD_SYNC"]["ID_PROVIDER_INPN"]
if not id_provider_inpn in auth_manager:
raise GeonatureApiError(
f"Identity provider named {id_provider_inpn} is not registered ! "
)
raise GeonatureApiError(f"Identity provider named {id_provider_inpn} is not registered ! ")
inpn_identity_provider = auth_manager.get_provider(id_provider_inpn)

organism_id = info_user["codeOrganisme"]
Expand All @@ -280,9 +270,7 @@ def insert_user_and_org(info_user, update_user_organism: bool = True):
assert user_id is not None and user_login is not None
except AssertionError:
log.error("'CAS ERROR: no ID or LOGIN provided'")
raise CasAuthentificationError(
"CAS ERROR: no ID or LOGIN provided", status_code=500
)
raise CasAuthentificationError("CAS ERROR: no ID or LOGIN provided", status_code=500)

# Reconciliation avec base GeoNature
if organism_id:
Expand Down Expand Up @@ -314,10 +302,7 @@ def insert_user_and_org(info_user, update_user_organism: bool = True):
user = existing_user or db.session.get(User, user_id)

if not user.groups:
if (
current_app.config["MTD_SYNC"]["USERS_CAN_SEE_ORGANISM_DATA"]
and organism_id
):
if current_app.config["MTD_SYNC"]["USERS_CAN_SEE_ORGANISM_DATA"] and organism_id:
# group socle 2 - for a user associated to an organism if users can see data from their organism
group_id = current_app.config["MTD_SYNC"]["ID_USER_SOCLE_2"]
else:
Expand Down
4 changes: 1 addition & 3 deletions src/mtd_sync/mtd_webservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@ def get_jdd_by_user_id(id_user):
assert r.status_code == 200
except AssertionError:
raise GeonatureApiError(
message="Error with the MTD Web Service (JDD), status_code: {}".format(
r.status_code
)
message="Error with the MTD Web Service (JDD), status_code: {}".format(r.status_code)
)
return r.content

Expand Down
18 changes: 6 additions & 12 deletions src/mtd_sync/xml_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,13 @@ def parse_acquisition_framwork_xml(xml):
def parse_acquisition_framework(ca):
# We extract all the required informations from the different tags of the XML file
ca_uuid = get_tag_content(ca, "identifiantCadre")
ca_name_max_length = (
TAcquisitionFramework.acquisition_framework_name.property.columns[0].type.length
)
ca_name_max_length = TAcquisitionFramework.acquisition_framework_name.property.columns[
0
].type.length
ca_name = get_tag_content(ca, "libelle")[: ca_name_max_length - 1]
ca_desc = get_tag_content(ca, "description", default_value="")
date_info = ca.find(namespace + "ReferenceTemporelle")
ca_create_date = get_tag_content(
ca, "dateCreationMtd", default_value=datetime.datetime.now()
)
ca_create_date = get_tag_content(ca, "dateCreationMtd", default_value=datetime.datetime.now())
ca_update_date = get_tag_content(ca, "dateMiseAJourMtd")
ca_start_date = get_tag_content(
date_info, "dateLancement", default_value=datetime.datetime.now()
Expand Down Expand Up @@ -139,15 +137,11 @@ def parse_jdd_xml(xml):
dataset_name = get_tag_content(jdd, "libelle")
dataset_shortname = get_tag_content(jdd, "libelleCourt", default_value="")
dataset_desc = get_tag_content(jdd, "description", default_value="")
terrestrial_domain = get_tag_content(
jdd, "domaineTerrestre", default_value=False
)
terrestrial_domain = get_tag_content(jdd, "domaineTerrestre", default_value=False)
marine_domain = get_tag_content(jdd, "domaineMarin", default_value=False)
data_type = get_tag_content(jdd, "typeDonnees")
collect_data_type = get_tag_content(jdd, "typeDonneesCollectees")
create_date = get_tag_content(
jdd, "dateCreation", default_value=datetime.datetime.now()
)
create_date = get_tag_content(jdd, "dateCreation", default_value=datetime.datetime.now())
update_date = get_tag_content(jdd, "dateRevision")
attributs_additionnels_node = jdd.find(namespace + "attributsAdditionnels")

Expand Down

0 comments on commit 59335b2

Please sign in to comment.