Skip to content

Commit

Permalink
test(back): add test for fieldmapping context
Browse files Browse the repository at this point in the history
- Test upload_route with context parameter

Reviewed-by: andriacap
  • Loading branch information
andriacap committed Jan 3, 2025
1 parent 85dca11 commit 2edacce
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions backend/geonature/tests/imports/test_imports_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from operator import or_
from functools import reduce
import csv
import json

from geonature.core.imports.checks.errors import ImportCodeError
import pytest
Expand Down Expand Up @@ -583,6 +584,26 @@ def test_import_upload(self, users, datasets):
assert imprt.source_file is not None
assert imprt.full_file_name == "simple_file.csv"

with open(tests_path / "files" / "synthese" / "simple_file.csv", "rb") as f:
fields_to_map = {
"nom_cite": {"column_src": "nom_cite", "default_value": "test_nomcite"},
"altitude_max": {"column_src": "altitude_max", "default_value": 10},
}
data = {
"file": (f, "simple_file.csv"),
"datasetId": datasets["own_dataset"].id_dataset,
"fieldsToMap": json.dumps(fields_to_map),
}
r = self.client.post(
url_for("import.upload_file"),
data=data,
headers=Headers({"Content-Type": "multipart/form-data"}),
)
assert r.status_code == 200, r.data

imprt = db.session.get(TImports, r.json["id_import"])
assert imprt.fieldmapping == fields_to_map

def test_import_error(self, users, datasets):
set_logged_user(self.client, users["user"])
with open(tests_path / "files" / "synthese" / "empty.csv", "rb") as f:
Expand Down

0 comments on commit 2edacce

Please sign in to comment.