Skip to content

Commit 6148d82

Browse files
author
Sergio García Prado
committed
ISSUE #?
* Increase coverage.
1 parent d875151 commit 6148d82

File tree

3 files changed

+16
-11
lines changed
  • packages/core
    • minos-microservice-aggregate
    • minos-microservice-common/minos/common/model

3 files changed

+16
-11
lines changed

packages/core/minos-microservice-aggregate/minos/aggregate/entities/refs/models.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,6 @@ def __getitem__(self, item: str) -> Any:
7878
try:
7979
return super().__getitem__(item)
8080
except KeyError as exc:
81-
if item == "data":
82-
raise exc
83-
8481
if item == "uuid":
8582
return self.uuid
8683

@@ -196,6 +193,14 @@ def uuid(self) -> UUID:
196193
return self.data
197194
return self.data.uuid
198195

196+
@uuid.setter
197+
def uuid(self, value: UUID) -> None:
198+
"""Set the uuid that identifies the ``Model``.
199+
200+
:return: This method does not return anything.
201+
"""
202+
raise NotImplementedError
203+
199204
@property
200205
def data_cls(self) -> Optional[type]:
201206
"""Get data class if available.

packages/core/minos-microservice-aggregate/tests/test_aggregate/test_entities/test_refs/test_models.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,12 @@ def test_uuid_getitem(self):
8484

8585
self.assertEqual(uuid, value["uuid"])
8686

87+
def test_model_getitem_raises(self):
88+
value = Ref(Bar(uuid4(), 1))
89+
90+
with self.assertRaises(KeyError):
91+
value["year"]
92+
8793
def test_uuid_setitem(self):
8894
uuid_1 = uuid4()
8995
uuid_2 = uuid4()

packages/core/minos-microservice-common/minos/common/model/abc.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -243,19 +243,13 @@ def __setattr__(self, key: str, value: Any) -> None:
243243
if key not in self._fields:
244244
raise AttributeError(f"{type(self).__name__!r} does not contain the {key!r} attribute.")
245245

246-
try:
247-
self[key] = value
248-
except KeyError as exc:
249-
raise AttributeError(str(exc))
246+
self[key] = value
250247

251248
def __getattr__(self, item: str) -> Any:
252249
if item.startswith("_") or item not in self._fields:
253250
raise AttributeError(f"{type(self).__name__!r} does not contain the {item!r} attribute.")
254251

255-
try:
256-
return self[item]
257-
except KeyError as exc:
258-
raise AttributeError(str(exc))
252+
return self[item]
259253

260254
# noinspection PyMethodParameters
261255
@property_or_classproperty

0 commit comments

Comments
 (0)