Skip to content

Commit

Permalink
Tox fixes for v0.9.0
Browse files Browse the repository at this point in the history
  • Loading branch information
subhashb committed Feb 18, 2022
1 parent 4734377 commit 7c492c1
Show file tree
Hide file tree
Showing 20 changed files with 44 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/protean/adapters/email/sendgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def send_email(self, message):
logger.debug("Email pushed to SendGrid successfully.")
except HTTPError as e:
logger.error(f"{e}: {e.to_dict}")
raise SendError(f"Exception: HTTPError - Failed to send email - str(e)")
raise SendError(f"Exception: HTTPError - Failed to send email - {str(e)}")
except Exception as e:
logger.error(f"Exception: Error while sending email: {e}")
raise SendError(f"Exception: Failed to send email - str(e)")
raise SendError(f"Exception: Failed to send email - {str(e)}")

return True
4 changes: 2 additions & 2 deletions src/protean/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ def __new__(cls, *args, **kwargs):
raise TypeError("BaseContainer cannot be instantiated")
return super().__new__(cls)

def __init__(self, *template, **kwargs):
def __init__(self, *template, **kwargs): # noqa: C901
"""
Initialise the container.
Expand Down Expand Up @@ -340,5 +340,5 @@ def __init__(self, *args, **kwargs) -> None:

self._events = []

def raise_(self, event: "BaseEvent") -> None:
def raise_(self, event) -> None:
self._events.append(event)
2 changes: 1 addition & 1 deletion src/protean/core/event_sourced_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def __new__(cls, *args, **kwargs):
raise TypeError("BaseEventSourcedRepository cannot be instantiated")
return super().__new__(cls)

def __init__(self, domain: "Domain") -> None:
def __init__(self, domain) -> None:
self._domain = domain

def add(self, aggregate: BaseEventSourcedAggregate) -> None:
Expand Down
4 changes: 2 additions & 2 deletions src/protean/core/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ def __new__(cls, *args, **kwargs):
raise TypeError("BaseRepository cannot be instantiated")
return super().__new__(cls)

def __init__(self, domain: "Domain", provider: "BaseProvider") -> None:
def __init__(self, domain, provider) -> None:
self._domain = domain
self._provider = provider

@property
@lru_cache()
def _model(self) -> "BaseModel":
def _model(self):
"""Retrieve Model class connected to Entity"""
# If a model was associated with the aggregate record, give it a higher priority
# and do not bake a new model class from aggregate/entity attributes
Expand Down
2 changes: 1 addition & 1 deletion src/protean/core/unit_of_work.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def start(self):
self._in_progress = True
_uow_context_stack.push(self)

def commit(self):
def commit(self): # noqa: C901
# Raise error if there the Unit Of Work is not active
logger.debug(f"Committing {self}...")
if not self._in_progress:
Expand Down
2 changes: 1 addition & 1 deletion src/protean/server/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@


class Engine:
def __init__(self, domain: "Domain", test_mode: str = False) -> None:
def __init__(self, domain, test_mode: str = False) -> None:
self.domain = domain
self.test_mode = test_mode

Expand Down
2 changes: 1 addition & 1 deletion src/protean/server/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class Subscription:

def __init__(
self,
engine: "Engine",
engine,
subscriber_id: str,
stream_name: str,
handler: Union[BaseEventHandler, BaseCommandHandler],
Expand Down
30 changes: 16 additions & 14 deletions src/protean/utils/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
from typing import Callable, Dict, Union
from uuid import uuid4

from protean import fields
from protean.container import BaseContainer, OptionsMixin
from protean.core.command import BaseCommand
from protean.core.event import BaseEvent
from protean.core.event_sourced_aggregate import BaseEventSourcedAggregate
from protean.core.unit_of_work import UnitOfWork
from protean.core.value_object import BaseValueObject
from protean.exceptions import ConfigurationError, IncorrectUsageError
from protean.fields import Auto, DateTime, Dict, Integer, String, ValueObject
from protean.globals import current_domain, g
from protean.reflection import has_id_field, id_field
from protean.utils import fully_qualified_name
Expand All @@ -26,22 +26,24 @@ class MessageType(Enum):


class MessageMetadata(BaseValueObject):
kind = String(max_length=7, choices=MessageType) # FIXME Make this field mandatory?
owner = String(max_length=50)
schema_version = Integer()
kind = fields.String(
max_length=7, choices=MessageType
) # FIXME Make this field mandatory?
owner = fields.String(max_length=50)
schema_version = fields.Integer()

origin_stream_name = String()
origin_stream_name = fields.String()


class CoreMessage(BaseContainer):
global_position = Auto(increment=True, identifier=True)
position = Integer()
time = DateTime()
id = Auto()
stream_name = String(max_length=255)
type = String()
data = Dict()
metadata = ValueObject(MessageMetadata)
global_position = fields.Auto(increment=True, identifier=True)
position = fields.Integer()
time = fields.DateTime()
id = fields.Auto()
stream_name = fields.String(max_length=255)
type = fields.String()
data = fields.Dict()
metadata = fields.ValueObject(MessageMetadata)


class Message(CoreMessage, OptionsMixin): # FIXME Remove OptionsMixin
Expand All @@ -52,7 +54,7 @@ class Message(CoreMessage, OptionsMixin): # FIXME Remove OptionsMixin
- Serialization and De-serialization
"""

expected_version = Integer()
expected_version = fields.Integer()

@classmethod
def derived_metadata(cls, new_message_type: str) -> Dict:
Expand Down
2 changes: 1 addition & 1 deletion tests/adapters/event_store/message_db_event_store/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_error_on_message_db_initialization(self):

with pytest.raises(ConfigurationError) as exc:
domain.event_store.store._write(
"testStream-123", "Event1", {"foo": f"bar"}, {"kind": "EVENT"}
"testStream-123", "Event1", {"foo": "bar"}, {"kind": "EVENT"}
)

assert 'FATAL: database "dummy" does not exist' in str(exc.value)
Expand Down
2 changes: 1 addition & 1 deletion tests/command/test_automatic_stream_association.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def test_automatic_association_of_events_with_aggregate_and_stream():
assert Activate.meta_.aggregate_cls is None
assert Activate.meta_.stream_name == "user"

assert Subscribe.meta_.aggregate_cls == None
assert Subscribe.meta_.aggregate_cls is None
assert Subscribe.meta_.stream_name == "subscriptions"

assert Send.meta_.aggregate_cls is None
Expand Down
4 changes: 2 additions & 2 deletions tests/command/test_command_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_command_definition_without_aggregate_or_stream(test_domain):
)
assert exc.value.messages == {
"_entity": [
f"Command `Register` needs to be associated with an aggregate or a stream"
"Command `Register` needs to be associated with an aggregate or a stream"
]
}

Expand All @@ -48,7 +48,7 @@ class Meta:

try:
test_domain.register(AbstractCommand)
except:
except Exception:
pytest.fail(
"Abstract commands should be definable without being associated with an aggregate or a stream"
)
Expand Down
2 changes: 1 addition & 1 deletion tests/event/test_automatic_stream_association.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def test_automatic_association_of_events_with_aggregate_and_stream():
assert Activated.meta_.aggregate_cls is None
assert Activated.meta_.stream_name == "user"

assert Subscribed.meta_.aggregate_cls == None
assert Subscribed.meta_.aggregate_cls is None
assert Subscribed.meta_.stream_name == "subscriptions"

assert Sent.meta_.aggregate_cls is None
Expand Down
2 changes: 1 addition & 1 deletion tests/event/test_event_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_event_definition_without_aggregate_or_stream(test_domain):

assert exc.value.messages == {
"_entity": [
f"Event `UserLoggedIn` needs to be associated with an aggregate or a stream"
"Event `UserLoggedIn` needs to be associated with an aggregate or a stream"
]
}

Expand Down
2 changes: 1 addition & 1 deletion tests/event_sourced_aggregates/test_applying_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,5 +105,5 @@ def sent(self, _: Sent) -> None:
pass

assert exc.value.messages == {
"_entity": [f"Apply method is missing Event class argument"]
"_entity": ["Apply method is missing Event class argument"]
}
2 changes: 1 addition & 1 deletion tests/event_store/test_appending_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_command_submission_without_aggregate(test_domain):
)
assert exc.value.messages == {
"_entity": [
f"Command `Register` needs to be associated with an aggregate or a stream"
"Command `Register` needs to be associated with an aggregate or a stream"
]
}

Expand Down
4 changes: 2 additions & 2 deletions tests/field/test_auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class AutoTest(BaseAggregate):
test_domain.register(AutoTest)

auto1 = AutoTest()
assert auto1.auto_field == None # Ensure value is unset before saving
assert auto1.auto_field is None # Ensure value is unset before saving
test_domain.repository_for(AutoTest).add(auto1)
refreshed_auto1 = test_domain.repository_for(AutoTest)._dao.query.all().items[0]
assert refreshed_auto1.auto_field == 1
Expand All @@ -62,7 +62,7 @@ class AutoTest(BaseAggregate):
test_domain.register(AutoTest)

auto1 = AutoTest()
assert auto1.auto_field == None # Ensure value is unset before saving
assert auto1.auto_field is None # Ensure value is unset before saving
test_domain.repository_for(AutoTest).add(auto1)
refreshed_auto1 = test_domain.repository_for(AutoTest)._dao.query.all().items[0]
assert refreshed_auto1.auto_field == 1
Expand Down
8 changes: 4 additions & 4 deletions tests/field/test_field_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,8 +320,8 @@ def test_type_casting(self):
def test_null_values(self):
birthday = Date()

assert birthday._load(None) == None
assert birthday._load("") == None
assert birthday._load(None) is None
assert birthday._load("") is None

def test_disallowing_datetime(self):
birthday = Date()
Expand Down Expand Up @@ -379,8 +379,8 @@ def test_type_casting(self):
def test_null_values(self):
created_at = DateTime()

assert created_at._load(None) == None
assert created_at._load("") == None
assert created_at._load(None) is None
assert created_at._load("") is None


class TestTextField:
Expand Down
4 changes: 2 additions & 2 deletions tests/message/test_origin_stream_name_in_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def test_origin_stream_name_in_event_from_command_without_origin_stream_name(use
name="John Doe",
)
)
assert event_message.metadata.origin_stream_name == None
assert event_message.metadata.origin_stream_name is None


def test_origin_stream_name_in_event_from_command_with_origin_stream_name(user_id):
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_origin_stream_name_in_aggregate_event_from_command_without_origin_strea
),
)

assert event_message.metadata.origin_stream_name == None
assert event_message.metadata.origin_stream_name is None


def test_origin_stream_name_in_aggregate_event_from_command_with_origin_stream_name(
Expand Down
2 changes: 1 addition & 1 deletion tests/query/test_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def test_last(self, test_domain):
query = person_repo._dao.query.order_by("age")
assert query.last.id == 2

def test_first_with_cache(self, test_domain):
def test_last_with_cache(self, test_domain):
"""Test that the first item is retrieved correctly from the resultset"""
person_repo = test_domain.repository_for(Person)

Expand Down
2 changes: 1 addition & 1 deletion tests/test_brokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_that_event_is_persisted_on_publish(self, mocker, test_domain):
messages = test_domain.event_store.store.read("person")

assert len(messages) == 1
messages[0].stream_name == f"person-1234"
messages[0].stream_name == "person-1234"


class TestBrokerSubscriberInitialization:
Expand Down

0 comments on commit 7c492c1

Please sign in to comment.