Skip to content

Commit

Permalink
chore: typing improvements and code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
andreyrcdias committed Oct 25, 2022
1 parent 2d82646 commit 4df0c7d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
36 changes: 19 additions & 17 deletions tests/conftest.py
Expand Up @@ -22,18 +22,20 @@


@pytest.fixture(scope="session")
def uow():
def uow() -> PocUnitOfWork:
bootstrap()
return PocUnitOfWork()


@pytest.fixture(scope="session")
def message_broker():
def message_broker() -> RedisMessageBroker:
return RedisMessageBroker()


@pytest.fixture(scope="session")
def message_bus(uow, example_event_handlers, example_command_handlers):
def message_bus(
uow, example_event_handlers, example_command_handlers
) -> MessageBus:
return MessageBus.create(
uow=uow,
event_handlers=example_event_handlers,
Expand All @@ -43,60 +45,60 @@ def message_bus(uow, example_event_handlers, example_command_handlers):


@pytest.fixture
def base_dir():
return kingdom_sdk._get_base_dir() # noqa
def base_dir() -> str:
return kingdom_sdk._get_base_dir()


@pytest.fixture
def src_dir():
return kingdom_sdk._get_src_dir() # noqa
def src_dir() -> str:
return kingdom_sdk._get_src_dir()


@pytest.fixture
def poc_dir(base_dir):
def poc_dir(base_dir) -> str:
return os.path.join(base_dir, "tests/poc/")


@pytest.fixture
def query_path(poc_dir):
def query_path(poc_dir) -> str:
return os.path.join(poc_dir, "context_example/queries/query.sql")


@pytest.fixture
def example_entity():
def example_entity() -> ExampleEntity:
return ExampleEntity.create(name="created")


@pytest.fixture
def example_aggregate(example_entity):
def example_aggregate(example_entity) -> ExampleAggregate:
return ExampleAggregate.create(value=1.0, reference=example_entity)


@pytest.fixture
def example_value_object():
def example_value_object() -> ExampleVO:
return ExampleVO.create(field="immutable")


@pytest.fixture
def example_command():
def example_command() -> CreateExampleAggregate:
return CreateExampleAggregate.create(name="raised", value=1.0)


@pytest.fixture
def example_unhandlable_command():
def example_unhandlable_command() -> ExemplifyUnhandlableCommand:
return ExemplifyUnhandlableCommand.create()


@pytest.fixture(scope="session")
def example_command_handlers():
def example_command_handlers() -> dict:
return {CreateExampleAggregate: MagicMock()}


@pytest.fixture
def example_event():
def example_event() -> ExampleAggregateCreated:
return ExampleAggregateCreated.create(id=uuid4(), name="raised")


@pytest.fixture(scope="session")
def example_event_handlers():
def example_event_handlers() -> dict:
return {ExampleAggregateCreated: [MagicMock(), MagicMock()]}
2 changes: 1 addition & 1 deletion tests/poc/context_example/bootstrap.py
Expand Up @@ -8,5 +8,5 @@

def bootstrap() -> MetaData:
return auto_start_mappers(
os.path.join(kingdom_sdk._get_base_dir(), "tests/poc/") # noqa
os.path.join(kingdom_sdk._get_base_dir(), "tests/poc/")
)
1 change: 0 additions & 1 deletion tests/poc/context_example/event.py
Expand Up @@ -2,7 +2,6 @@

from dataclasses import dataclass
from typing import Any
from uuid import UUID # noqa: F401

from kingdom_sdk.domain.message import Event
from kingdom_sdk.utils import time
Expand Down
6 changes: 3 additions & 3 deletions tests/poc/context_example/model.py
Expand Up @@ -3,7 +3,7 @@
from dataclasses import dataclass
from datetime import datetime
from typing import Any
from uuid import uuid4
from uuid import UUID, uuid4

from kingdom_sdk.domain.aggregate import Aggregate
from kingdom_sdk.domain.entity import Entity
Expand All @@ -17,7 +17,7 @@ class ExampleEntity(Entity):

def __init__(
self,
id: UUID, # noqa
id: UUID,
version: int,
is_discarded: bool,
registered_at: datetime,
Expand Down Expand Up @@ -71,7 +71,7 @@ class ExampleAggregate(Aggregate):

def __init__(
self,
id: UUID, # noqa
id: UUID,
version: int,
is_discarded: bool,
registered_at: datetime,
Expand Down
2 changes: 1 addition & 1 deletion tests/poc/loader_example/my_module.py
@@ -1,2 +1,2 @@
def return_ok():
def return_ok() -> str:
return "It works!"

0 comments on commit 4df0c7d

Please sign in to comment.