Skip to content

Commit

Permalink
test: adjust the way to initiliaze the impor
Browse files Browse the repository at this point in the history
  • Loading branch information
edelclaux committed Jan 3, 2025
1 parent bb72f06 commit 57d8865
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 27 deletions.
26 changes: 13 additions & 13 deletions backend/geonature/core/gn_meta/models/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,21 +201,21 @@ def filter_by_scope(cls, scope, *, query, user=None):
elif scope in (1, 2):
ors = [
cls.id_digitizer == user.id_role,
# cls.cor_dataset_actor.any(id_role=user.id_role),
# cls.acquisition_framework.has(id_digitizer=user.id_role),
# cls.acquisition_framework.has(
# TAcquisitionFramework.cor_af_actor.any(id_role=user.id_role),
# ),
cls.cor_dataset_actor.any(id_role=user.id_role),
cls.acquisition_framework.has(id_digitizer=user.id_role),
cls.acquisition_framework.has(
TAcquisitionFramework.cor_af_actor.any(id_role=user.id_role),
),
]
# if organism is None => do not filter on id_organism even if level = 2
# if scope == 2 and user.id_organisme is not None:
# ors += [
# cls.cor_dataset_actor.any(id_organism=user.id_organisme),
# cls.acquisition_framework.has(
# TAcquisitionFramework.cor_af_actor.any(id_organism=user.id_organisme),
# ),
# ]
# whereclause = or_(*ors)
if scope == 2 and user.id_organisme is not None:
ors += [
cls.cor_dataset_actor.any(id_organism=user.id_organisme),
cls.acquisition_framework.has(
TAcquisitionFramework.cor_af_actor.any(id_organism=user.id_organisme),
),
]
whereclause = or_(*ors)
return query.where(whereclause)

@qfilter(query=True)
Expand Down
4 changes: 2 additions & 2 deletions backend/geonature/core/imports/checks/dataframe/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ def check_datasets(
TDatasets.filter_by_creatable(
user=imprt.authors[0], module_code=module_code, object_code=object_code
)
# .where(TDatasets.unique_dataset_id.in_(uuid))
# .options(sa.orm.raiseload("*"))
.where(TDatasets.unique_dataset_id.in_(uuid))
.options(sa.orm.raiseload("*"))
)
.scalars()
.all()
Expand Down
29 changes: 17 additions & 12 deletions backend/geonature/tests/imports/test_imports_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def autogenerate():

@pytest.fixture()
def import_dataset(datasets, import_file_name):

ds = datasets["own_dataset"]
if import_file_name == "nomenclatures_file.csv":
previous_data_origin = ds.nomenclature_data_origin
Expand Down Expand Up @@ -176,20 +177,24 @@ def import_dataset(datasets, import_file_name):


@pytest.fixture()
def uploaded_import(client, users):
def uploaded_import(client, datasets, users):
set_logged_user(client, users["user"])

filename = "valid_file.csv"
file = (open(tests_path / "files" / "synthese" / filename, "rb"), filename)

r = client.post(
url_for("import.upload_file", destination="synthese"),
data={"file": file},
)
assert r.status_code == 200, r.data
unset_logged_user(client)
# db.session.refresh(uploaded_import)
# return uploaded_import
# Upload step
test_file_name = "valid_file.csv"
with open(tests_path / "files" / "synthese" / test_file_name, "rb") as f:
f.seek(0)
data = {
"file": (f, test_file_name),
"datasetId": datasets["own_dataset"].id_dataset,
}
r = client.post(
url_for("import.upload_file"),
data=data,
headers=Headers({"Content-Type": "multipart/form-data"}),
)
assert r.status_code == 200, r.data
return db.session.get(TImports, r.get_json()["id_import"])


@pytest.fixture()
Expand Down

0 comments on commit 57d8865

Please sign in to comment.