From 47ef57391781cf4eab054b8d3ec1f9463919b9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89loi=20Rivard?= Date: Fri, 5 Apr 2024 15:21:35 +0200 Subject: [PATCH] refactor: fix coverage --- canaille/backends/memory/models.py | 15 ++------------- canaille/backends/sql/models.py | 9 +++++---- 2 files changed, 7 insertions(+), 17 deletions(-) diff --git a/canaille/backends/memory/models.py b/canaille/backends/memory/models.py index 56528f0c..4cc3bfe2 100644 --- a/canaille/backends/memory/models.py +++ b/canaille/backends/memory/models.py @@ -150,9 +150,6 @@ class MemoryModel(BackendModel): mirror_attribute, model ).setdefault(self.id, set()) for subinstance_id in self.listify(self._state.get(attribute, [])): - if not subinstance_id or subinstance_id not in self.index(model): - continue - # add the current objet in the subinstance state subinstance_state = self.index(model)[subinstance_id] subinstance_state.setdefault(mirror_attribute, []) @@ -171,11 +168,7 @@ class MemoryModel(BackendModel): for attribute in self.model_attributes: attribute_values = self.listify(old_state.get(attribute, [])) for value in attribute_values: - if ( - value in self.attribute_index(attribute) - and self.id in self.attribute_index(attribute)[value] - ): - self.attribute_index(attribute)[value].remove(self.id) + self.attribute_index(attribute)[value].remove(self.id) # update the mirror attributes of the submodel instances model, mirror_attribute = self.model_attributes[attribute] @@ -186,16 +179,12 @@ class MemoryModel(BackendModel): mirror_attribute, model ).setdefault(self.id, set()) for subinstance_id in self.index()[self.id].get(attribute, []): - if subinstance_id not in self.index(model): - continue - # remove the current objet from the subinstance state subinstance_state = self.index(model)[subinstance_id] subinstance_state[mirror_attribute].remove(self.id) # remove the current objet from the subinstance index - if subinstance_id in mirror_attribute_index: - mirror_attribute_index.remove(subinstance_id) + mirror_attribute_index.remove(subinstance_id) # update the index for each attribute for attribute in self.attributes: diff --git a/canaille/backends/sql/models.py b/canaille/backends/sql/models.py index 531c484c..d6168bbf 100644 --- a/canaille/backends/sql/models.py +++ b/canaille/backends/sql/models.py @@ -193,10 +193,11 @@ class User(canaille.core.models.User, Base, SqlAlchemyModel): # not super generic, but we can improve this when we have # type checking and/or pydantic for the models if attribute == "groups": - if models.Group.get(id=value): - return models.Group.get(id=value) - elif models.Group.get(display_name=value): - return models.Group.get(display_name=value) + return ( + models.Group.get(id=value) + or models.Group.get(display_name=value) + or None + ) return value def match_filter(self, filter):