Skip to content

Commit

Permalink
Misc fixes and improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Jul 25, 2024
1 parent f2deb99 commit f33877d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 22 deletions.
2 changes: 2 additions & 0 deletions src/protean/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from .core.aggregate import apply, atomic_change
from .core.entity import invariant
from .core.event import BaseEvent
from .core.model import BaseModel
from .core.queryset import Q, QuerySet
from .core.unit_of_work import UnitOfWork
Expand All @@ -12,6 +13,7 @@
from .utils.mixins import handle

__all__ = [
"BaseEvent",
"BaseModel",
"Domain",
"Engine",
Expand Down
17 changes: 0 additions & 17 deletions src/protean/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,23 +79,6 @@ class ValidationError(ProteanException):
"""


class UsecaseExecutionError(Exception):
"""Raised when a failure response is encountered on executing a usecase
:param value: a tuple comprising of the error code and error message
:type value: tuple
:param orig_exc: Optional original exception raised in the usecase
:param orig_trace: Optional trace of the original exception in the usecase
"""

def __init__(self, value, orig_exc=None, orig_trace=None, **kwargs):
self.value = value
self.orig_exc = orig_exc
self.orig_trace = orig_trace

super().__init__(**kwargs)


class SendError(Exception):
"""Raised on email dispatch failure."""

Expand Down
10 changes: 5 additions & 5 deletions tests/reflection/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@
from protean.core.aggregate import BaseAggregate
from protean.exceptions import IncorrectUsageError
from protean.fields import Integer, String
from protean.utils.reflection import declared_fields
from protean.utils.reflection import fields


class Person(BaseAggregate):
name = String(max_length=50, required=True)
age = Integer()


def test_declared_fields():
assert len(declared_fields(Person)) == 3
assert all(key in declared_fields(Person) for key in ["name", "age", "id"])
def test_fields():
assert len(fields(Person)) == 4
assert all(key in fields(Person) for key in ["_version", "name", "age", "id"])


def test_fields_on_non_element():
class Dummy:
pass

with pytest.raises(IncorrectUsageError) as exception:
declared_fields(Dummy)
fields(Dummy)

assert exception.value.messages == {
"field": [
Expand Down

0 comments on commit f33877d

Please sign in to comment.