Skip to content

Commit

Permalink
refact: test synthese import jdd
Browse files Browse the repository at this point in the history
Based on Elie's review

Reviewed-by: andriac
  • Loading branch information
andriacap committed Mar 13, 2024
1 parent f88d45d commit a2cb5a9
Showing 1 changed file with 11 additions and 22 deletions.
33 changes: 11 additions & 22 deletions backend/geonature/tests/imports/test_imports_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def new_import(synthese_destination, users, import_dataset):


@pytest.fixture()
def uploaded_import(client, new_import, datasets, import_file_name):
def uploaded_import(new_import, datasets, import_file_name):
with db.session.begin_nested():
with open(tests_path / "files" / "synthese" / import_file_name, "rb") as f:
f.seek(0)
Expand All @@ -161,7 +161,6 @@ def uploaded_import(client, new_import, datasets, import_file_name):
else:
new_import.full_file_name = "valid_file.csv"
new_import.source_file = content
# data = bytes_csv_to_dict(content)
return new_import


Expand Down Expand Up @@ -220,27 +219,16 @@ def loaded_import(client, field_mapped_import):

@pytest.fixture()
def content_mapped_import(client, import_file_name, loaded_import):
if import_file_name == "jdd_to_import_file.csv":
set_logged_user(client, loaded_import.authors[0])
contentmapping = ContentMapping.query.filter_by(label="Nomenclatures SINP (labels)").one()
r = client.post(
url_for("import.set_import_content_mapping", import_id=loaded_import.id_import),
data=contentmapping.values,
with db.session.begin_nested():
loaded_import.contentmapping = (
ContentMapping.query.filter_by(label="Nomenclatures SINP (labels)").one().values
)
assert r.status_code == 200, r.data
unset_logged_user(client)
db.session.refresh(loaded_import)
else:
with db.session.begin_nested():
loaded_import.contentmapping = (
ContentMapping.query.filter_by(label="Nomenclatures SINP (labels)").one().values
if import_file_name == "empty_nomenclatures_file.csv":
loaded_import.contentmapping["STADE_VIE"].update(
{
"": "17", # Alevin
}
)
if import_file_name == "empty_nomenclatures_file.csv":
loaded_import.contentmapping["STADE_VIE"].update(
{
"": "17", # Alevin
}
)
return loaded_import


Expand Down Expand Up @@ -1303,7 +1291,8 @@ def test_import_jdd_file(self, imported_import):
imported_import,
{
# id_dataset errors
# The line 2 should not be error (should be the one selected jdd default)
("DATASET_NOT_AUTHORIZED", "unique_dataset_id", frozenset({2, 4})),
("DATASET_NOT_FOUND", "unique_dataset_id", frozenset({5})),
("DATASET_NOT_AUTHORIZED", "unique_dataset_id", frozenset({4})),
},
)

0 comments on commit a2cb5a9

Please sign in to comment.