diff --git a/src/protean/adapters/email/sendgrid.py b/src/protean/adapters/email/sendgrid.py index 10943b7b..de2fbea7 100644 --- a/src/protean/adapters/email/sendgrid.py +++ b/src/protean/adapters/email/sendgrid.py @@ -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 diff --git a/src/protean/container.py b/src/protean/container.py index f0f7d536..a262e33d 100644 --- a/src/protean/container.py +++ b/src/protean/container.py @@ -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. @@ -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) diff --git a/src/protean/core/event_sourced_repository.py b/src/protean/core/event_sourced_repository.py index 48f3dbb5..56b48abb 100644 --- a/src/protean/core/event_sourced_repository.py +++ b/src/protean/core/event_sourced_repository.py @@ -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: diff --git a/src/protean/core/repository.py b/src/protean/core/repository.py index 392234ab..e4973485 100644 --- a/src/protean/core/repository.py +++ b/src/protean/core/repository.py @@ -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 diff --git a/src/protean/core/unit_of_work.py b/src/protean/core/unit_of_work.py index 3af4443b..f38cd15f 100644 --- a/src/protean/core/unit_of_work.py +++ b/src/protean/core/unit_of_work.py @@ -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: diff --git a/src/protean/server/engine.py b/src/protean/server/engine.py index 267ecd51..70601e34 100644 --- a/src/protean/server/engine.py +++ b/src/protean/server/engine.py @@ -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 diff --git a/src/protean/server/subscription.py b/src/protean/server/subscription.py index bf4dd621..bc7f28bb 100644 --- a/src/protean/server/subscription.py +++ b/src/protean/server/subscription.py @@ -21,7 +21,7 @@ class Subscription: def __init__( self, - engine: "Engine", + engine, subscriber_id: str, stream_name: str, handler: Union[BaseEventHandler, BaseCommandHandler], diff --git a/src/protean/utils/mixins.py b/src/protean/utils/mixins.py index 1e4ac163..0969ae50 100644 --- a/src/protean/utils/mixins.py +++ b/src/protean/utils/mixins.py @@ -7,6 +7,7 @@ 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 @@ -14,7 +15,6 @@ 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 @@ -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 @@ -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: diff --git a/tests/adapters/event_store/message_db_event_store/tests.py b/tests/adapters/event_store/message_db_event_store/tests.py index a2acb8b3..6b538e4b 100644 --- a/tests/adapters/event_store/message_db_event_store/tests.py +++ b/tests/adapters/event_store/message_db_event_store/tests.py @@ -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) diff --git a/tests/command/test_automatic_stream_association.py b/tests/command/test_automatic_stream_association.py index 6e93e56c..1452ac1f 100644 --- a/tests/command/test_automatic_stream_association.py +++ b/tests/command/test_automatic_stream_association.py @@ -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 diff --git a/tests/command/test_command_meta.py b/tests/command/test_command_meta.py index 1b67144a..7d71cfd0 100644 --- a/tests/command/test_command_meta.py +++ b/tests/command/test_command_meta.py @@ -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" ] } @@ -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" ) diff --git a/tests/event/test_automatic_stream_association.py b/tests/event/test_automatic_stream_association.py index a2f18599..9f47ef1c 100644 --- a/tests/event/test_automatic_stream_association.py +++ b/tests/event/test_automatic_stream_association.py @@ -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 diff --git a/tests/event/test_event_meta.py b/tests/event/test_event_meta.py index ff570a03..75bd9e2a 100644 --- a/tests/event/test_event_meta.py +++ b/tests/event/test_event_meta.py @@ -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" ] } diff --git a/tests/event_sourced_aggregates/test_applying_events.py b/tests/event_sourced_aggregates/test_applying_events.py index 8b7d0e43..71439edc 100644 --- a/tests/event_sourced_aggregates/test_applying_events.py +++ b/tests/event_sourced_aggregates/test_applying_events.py @@ -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"] } diff --git a/tests/event_store/test_appending_commands.py b/tests/event_store/test_appending_commands.py index 172068e0..5ce9bec8 100644 --- a/tests/event_store/test_appending_commands.py +++ b/tests/event_store/test_appending_commands.py @@ -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" ] } diff --git a/tests/field/test_auto.py b/tests/field/test_auto.py index 84ce0011..0bcbf701 100644 --- a/tests/field/test_auto.py +++ b/tests/field/test_auto.py @@ -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 @@ -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 diff --git a/tests/field/test_field_types.py b/tests/field/test_field_types.py index a4edc5e5..1bc1fa92 100644 --- a/tests/field/test_field_types.py +++ b/tests/field/test_field_types.py @@ -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() @@ -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: diff --git a/tests/message/test_origin_stream_name_in_metadata.py b/tests/message/test_origin_stream_name_in_metadata.py index 0d23c3aa..8f800680 100644 --- a/tests/message/test_origin_stream_name_in_metadata.py +++ b/tests/message/test_origin_stream_name_in_metadata.py @@ -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): @@ -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( diff --git a/tests/query/test_queryset.py b/tests/query/test_queryset.py index 6127957f..60072deb 100644 --- a/tests/query/test_queryset.py +++ b/tests/query/test_queryset.py @@ -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) diff --git a/tests/test_brokers.py b/tests/test_brokers.py index 7673400e..2dffbee9 100644 --- a/tests/test_brokers.py +++ b/tests/test_brokers.py @@ -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: