Skip to content

Commit

Permalink
fix(test) : add temp fixture to set gn_imports.unique_dataset_id.disp…
Browse files Browse the repository at this point in the history
…lay to true.

This is required for testing the dataset mapping field even though it is deactivated for the moment.
  • Loading branch information
jacquesfize committed Oct 1, 2024
1 parent ae85450 commit 4d47bec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
23 changes: 19 additions & 4 deletions backend/geonature/tests/imports/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import pytest
from flask import g
from sqlalchemy import select
import sqlalchemy as sa

from geonature.core.gn_commons.models import TModules
from geonature.utils.env import db

from geonature.core.imports.models import Destination
from geonature.core.imports.models import BibFields, Destination


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -41,17 +41,20 @@ def default_synthese_destination(app, default_destination, synthese_destination)
@pytest.fixture(scope="session")
def list_all_module_dest_code():
module_code_dest = db.session.scalars(
select(TModules.module_code).join(Destination, Destination.id_module == TModules.id_module)
sa.select(TModules.module_code).join(
Destination, Destination.id_module == TModules.id_module
)
).all()
return module_code_dest


@pytest.fixture(scope="session")
def all_modules_destination(list_all_module_dest_code):

dict_modules_dest = {}

for module_code in list_all_module_dest_code:
query = select(Destination).filter(
query = sa.select(Destination).filter(
Destination.module.has(TModules.module_code == module_code)
)

Expand All @@ -60,3 +63,15 @@ def all_modules_destination(list_all_module_dest_code):
dict_modules_dest[module_code] = result

return dict_modules_dest


@pytest.fixture()
def display_unique_dataset_id():
"""
This fixture is temporary and must be removed when the UUID of a JDD can be mapped in the
fieldmapping step !
"""
query = (
sa.update(BibFields).where(BibFields.name_field == "unique_dataset_id").values(display=True)
)
db.session.execute(query)
4 changes: 3 additions & 1 deletion backend/geonature/tests/imports/test_imports_occhab.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,9 @@ def contentmapping(occhab_destination):


@pytest.fixture()
def uploaded_import(client, users, datasets, station, habitat, import_file_name):
def uploaded_import(
client, users, datasets, station, habitat, import_file_name, display_unique_dataset_id
):
with open(test_files_path / import_file_name, "rb") as f:
test_file_line_count = sum(1 for line in f) - 1 # remove headers
f.seek(0)
Expand Down
2 changes: 1 addition & 1 deletion backend/geonature/tests/imports/test_imports_synthese.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def autogenerate():


@pytest.fixture()
def import_dataset(datasets, import_file_name):
def import_dataset(datasets, import_file_name, display_unique_dataset_id):
ds = datasets["own_dataset"]
if import_file_name == "nomenclatures_file.csv":
previous_data_origin = ds.nomenclature_data_origin
Expand Down

0 comments on commit 4d47bec

Please sign in to comment.