From 926be2570950327324ffb5c8cd36ebfb58d40799 Mon Sep 17 00:00:00 2001 From: "joel.clement" Date: Wed, 7 Feb 2024 13:37:01 +0100 Subject: [PATCH] wip #96 delete --- .../gn_modulator/routes/utils/repository.py | 4 +--- backend/gn_modulator/schema/repositories.py | 20 ++++++++++++++++++- backend/gn_modulator/tests/test_repository.py | 9 ++++++++- 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/backend/gn_modulator/routes/utils/repository.py b/backend/gn_modulator/routes/utils/repository.py index c83cc61e..8270b01a 100644 --- a/backend/gn_modulator/routes/utils/repository.py +++ b/backend/gn_modulator/routes/utils/repository.py @@ -205,6 +205,4 @@ def get_page_number_and_list(module_code, object_code, value): id_role=id_role, ) - return get_list_rest( - module_code, object_code, additional_params={"page": page_number}, id_role=id_role - ) + return get_list_rest(module_code, object_code, additional_params={"page": page_number}) diff --git a/backend/gn_modulator/schema/repositories.py b/backend/gn_modulator/schema/repositories.py index 02368e08..d95b5fbe 100644 --- a/backend/gn_modulator/schema/repositories.py +++ b/backend/gn_modulator/schema/repositories.py @@ -232,7 +232,25 @@ def delete_row( # https://stackoverflow.com/questions/49794899/flask-sqlalchemy-delete-query-failing-with-could-not-evaluate-current-criteria?noredirect=1&lq=1 if not multiple: subquery_delete.one() - subquery_delete.delete(synchronize_session=False) + + res = subquery_delete.all() + + if not res: + return + + Model = self.Model() + + q_delete = Model.query + ors = [] + for r in res: + ands = [] + for pk_field_name in Model.pk_field_names(): + f = getattr(Model, pk_field_name) == getattr(r, pk_field_name) + ands.append(f) + ors.append(f) + + q_delete = q_delete.filter(sa.or_(*ors)) + q_delete.delete(synchronize_session=False) db.session.flush() if commit: diff --git a/backend/gn_modulator/tests/test_repository.py b/backend/gn_modulator/tests/test_repository.py index 3b9ff4bf..ffaf7ce1 100644 --- a/backend/gn_modulator/tests/test_repository.py +++ b/backend/gn_modulator/tests/test_repository.py @@ -7,6 +7,7 @@ - list ?? """ +import os import pytest from .utils.repository import test_schema_repository from .data import commons as data_commons @@ -41,6 +42,7 @@ def test_repo_gn_meta_ca(self): def test_repo_gn_meta_jdd(self): test_schema_repository("meta.jdd", data_meta.jdd(), data_meta.jdd_update()) + # @pytest.mark.skip() def test_repo_diag(self, users, passages_faune_with_diagnostic): sm = SchemaMethods("m_sipaf.diag") fields = ["scope", "id_diagnostic"] @@ -61,6 +63,7 @@ def test_repo_diag(self, users, passages_faune_with_diagnostic): assert True + # @pytest.mark.skip() def test_repo_pf_update(self, passages_faune_with_diagnostic): sm = SchemaMethods("m_sipaf.pf") @@ -72,6 +75,7 @@ def test_repo_pf_update(self, passages_faune_with_diagnostic): assert sm.is_new_data(m, data) is False sm.update_row(uuid_pf, data, "uuid_passage_faune", "m_sipaf") + # @pytest.mark.skip() def test_repo_diag_cloture(self, passages_faune_with_diagnostic): sm = SchemaMethods("m_sipaf.diag") sm_org = SchemaMethods("user.organisme") @@ -130,6 +134,7 @@ def test_repo_diag_cloture(self, passages_faune_with_diagnostic): assert sm.is_new_data(m, data) sm.update_row(m.id_diagnostic, data) + # @pytest.mark.skip() def test_repo_pf_rel(self, passages_faune_with_diagnostic, users): sm = SchemaMethods("m_sipaf.pf") uuids_filter_value = ";".join( @@ -261,6 +266,7 @@ def test_repo_pf_nomenclature_spe(self): res_nom = res["nomenclature_ouvrage_specificite"] assert res_nom is None + # @pytest.mark.skip() def test_repo_pf_cruved(self, passages_faune_with_diagnostic, users): sm = SchemaMethods("m_sipaf.pf") uuids_filter_value = ";".join( @@ -326,6 +332,7 @@ def test_repo_pf_filter_has_diagnostic(self, passages_faune_with_diagnostic, use res = sm.serialize_list(m_list, fields) assert len(res) == 2 + # @pytest.mark.skip() def test_repo_synthese_d_within( self, passages_faune_with_diagnostic, synthese_data, users, g_permissions ): @@ -377,7 +384,7 @@ def test_repo_synthese_scope(self, synthese_data, users, datasets): assert len(res[user]) == 9 assert all(r["scope"] == 2 for r in res[user]) - @pytest.mark.skip() + # @pytest.mark.skip() def test_repo_synthese_permission(self, synthese_sensitive_data, users, g_permissions): for key in synthese_sensitive_data: s = synthese_sensitive_data[key]