Skip to content

Commit

Permalink
ISSUE #?
Browse files Browse the repository at this point in the history
* Update to `[email protected]`
  • Loading branch information
Sergio García Prado committed Feb 3, 2022
1 parent 8a5f103 commit f387b1e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 83 deletions.
10 changes: 4 additions & 6 deletions microservice/language/python/init/config.yml.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@ service:
injections:
lock_pool: minos.common.PostgreSqlLockPool
postgresql_pool: minos.common.PostgreSqlPool
broker_publisher: minos.networks.BrokerPublisher
broker_consumer: minos.networks.BrokerConsumer
broker_pool: minos.networks.DynamicBrokerPool
broker_publisher: minos.plugins.kafka.InMemoryQueuedKafkaBrokerPublisher
broker_subscriber_builder: minos.plugins.kafka.InMemoryQueuedKafkaBrokerSubscriberBuilder
broker_pool: minos.networks.BrokerClientPool
transaction_repository: minos.aggregate.PostgreSqlTransactionRepository
event_repository: minos.aggregate.PostgreSqlEventRepository
snapshot_repository: minos.aggregate.PostgreSqlSnapshotRepository
saga_manager: minos.saga.SagaManager
discovery: minos.networks.DiscoveryConnector
services:
- minos.networks.BrokerProducerService
- minos.networks.BrokerConsumerService
- minos.networks.BrokerHandlerService
- minos.networks.RestService
- minos.networks.PeriodicTaskSchedulerService
Expand Down Expand Up @@ -56,6 +54,6 @@ saga:
storage:
path: ./{{ name }}.lmdb
discovery:
client: minos.networks.MinosDiscoveryClient
client: minos.plugins.minos_discovery.MinosDiscoveryClient
host: localhost
port: 5567
19 changes: 17 additions & 2 deletions microservice/language/python/init/src/aggregates.py.jinja
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
from uuid import (
UUID,
)

from minos.aggregate import (
Aggregate,
RootEntity,
)


class {{ aggregate }}(Aggregate):
"""{{ aggregate }} Aggregate class."""
class {{ aggregate }}(RootEntity):
"""{{ aggregate }} RootEntity class."""


class {{ aggregate }}Aggregate(Aggregate[{{ aggregate }}]):
"""{{ aggregate }}Aggregate class."""

@staticmethod
async def create() -> UUID:
"""Create a new instance."""
root = await {{ aggregate }}.create()
return root.uuid
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ from minos.networks import (
)

from ..aggregates import (
{{ aggregate }},
{{ aggregate }}Aggregate,
)


Expand All @@ -25,7 +25,7 @@ class {{ aggregate }}CommandService(CommandService):
:return: A ``Response`` instance.
"""
try:
instance = await {{ aggregate }}.create()
return Response({"uuid": instance.uuid })
uuid = await {{ aggregate }}Aggregate.create()
return Response({"uuid": uuid})
except Exception as exc:
raise ResponseException(f"An error occurred during {{ aggregate }} creation: {exc}")
14 changes: 7 additions & 7 deletions microservice/language/python/init/src/queries/services.py.jinja
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from minos.aggregate import (
AggregateDiff,
Event,
)
from minos.cqrs import (
QueryService,
Expand Down Expand Up @@ -31,8 +31,8 @@ class {{ aggregate }}QueryService(QueryService):
:param request: A request instance containing the aggregate difference.
:return: This method does not return anything.
"""
diff: AggregateDiff = await request.content()
print(diff)
event: Event = await request.content()
print(event)

@enroute.broker.event("{{ aggregate }}Updated")
async def {{ aggregate.lower() }}_updated(self, request: Request) -> None:
Expand All @@ -41,8 +41,8 @@ class {{ aggregate }}QueryService(QueryService):
:param request: A request instance containing the aggregate difference.
:return: This method does not return anything.
"""
diff: AggregateDiff = await request.content()
print(diff)
event: Event = await request.content()
print(event)

@enroute.broker.event("{{ aggregate }}Deleted")
async def {{ aggregate.lower() }}_deleted(self, request: Request) -> None:
Expand All @@ -51,5 +51,5 @@ class {{ aggregate }}QueryService(QueryService):
:param request: A request instance containing the aggregate difference.
:return: This method does not return anything.
"""
diff: AggregateDiff = await request.content()
print(diff)
event: Event = await request.content()
print(event)
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ from src import (
)

from minos.networks import (
InMemoryRequest,
Response,
)
from tests.utils import (
_FakeRequest,
build_dependency_injector,
)

Expand All @@ -33,7 +33,7 @@ class Test{{aggregate}}CommandService(unittest.IsolatedAsyncioTestCase):
async def test_create_{{ aggregate.lower() }}(self):
service = {{ aggregate }}CommandService()

request = _FakeRequest({})
request = InMemoryRequest({})
response = await service.create_{{ aggregate.lower() }}(request)

self.assertIsInstance(response, Response)
Expand Down
79 changes: 21 additions & 58 deletions microservice/language/python/init/tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,72 +1,35 @@
from __future__ import (
annotations, )
annotations,
)

from pathlib import (
Path, )
from typing import (
Optional, )
from uuid import UUID
from uuid import uuid4

from minos.common import CommandReply
from minos.common import DependencyInjector
from minos.common import InMemoryRepository
from minos.common import InMemorySnapshot
from minos.common import MinosBroker
from minos.common import MinosConfig
from minos.common import MinosSagaManager
from minos.common import Model
Path,
)

from minos.aggregate import (
InMemoryTransactionRepository,
InMemoryEventRepository,
InMemorySnapshotRepository,
)
from minos.common import (
DependencyInjector,
MinosConfig,
)
from minos.networks import (
Request, )


class _FakeRequest(Request):
"""For testing purposes"""
def __init__(self, content):
super().__init__()
self._content = content
self._user = uuid4()

@property
def user(self) -> Optional[UUID]:
"""For testing purposes"""
return self._user

async def content(self, **kwargs):
"""For testing purposes"""
return self._content

def __eq__(self, other: _FakeRequest) -> bool:
return self._content == other._content and self.user == other.user

def __repr__(self) -> str:
return str()


class _FakeBroker(MinosBroker):
"""For testing purposes."""
async def send(self, items: list[Model], **kwargs) -> None:
"""For testing purposes."""


class _FakeSagaManager(MinosSagaManager):
"""For testing purposes."""
async def _run_new(self, name: str, **kwargs) -> UUID:
"""For testing purposes."""

async def _load_and_run(self, reply: CommandReply, **kwargs) -> UUID:
"""For testing purposes."""
InMemoryBrokerPublisher,
InMemoryBrokerSubscriberBuilder,
)


def build_dependency_injector() -> DependencyInjector:
"""For testing purposes"""

return DependencyInjector(
build_config(),
saga_manager=_FakeSagaManager,
event_broker=_FakeBroker,
repository=InMemoryRepository,
snapshot=InMemorySnapshot,
broker_publisher=InMemoryBrokerPublisher,
transaction_repository=InMemoryTransactionRepository,
event_repository=InMemoryEventRepository,
snapshot_snapshot=InMemorySnapshotRepository,
)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ packages = [{ include = "src" }]

[tool.poetry.dependencies]
python = "^3.9"
minos-microservice-common = "^0.3.2"
minos-microservice-networks = "^0.3.2"
minos-microservice-aggregate = "^0.2.2"
minos-microservice-saga = "^0.3.5"
minos-microservice-cqrs = "^0.2.1"
minos-microservice-common = "^0.5.0"
minos-microservice-networks = "^0.5.0"
minos-microservice-aggregate = "^0.5.0"
minos-microservice-saga = "^0.5.0"
minos-microservice-cqrs = "^0.5.0"
minos-broker-kafka = "^0.5.0"
minos-discovery-minos = "^0.5.0"
typer = "^0.3.2"

[tool.poetry.dev-dependencies]
Expand Down

0 comments on commit f387b1e

Please sign in to comment.