Skip to content

Commit e703077

Browse files
author
Sergio García Prado
committed
ISSUE #346
* Fix all broken tests.
1 parent c210abb commit e703077

File tree

8 files changed

+35
-80
lines changed

8 files changed

+35
-80
lines changed

packages/core/minos-microservice-common/minos/common/config/v1.py

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -128,21 +128,7 @@ def _get_injections(self) -> list[type[InjectableMixin]]:
128128
except MinosConfigException:
129129
injections = list()
130130

131-
old = [import_module(classname) for classname in injections]
132-
from ..injections import (
133-
InjectableMixin,
134-
)
135-
from ..pools import (
136-
PoolFactory,
137-
)
138-
139-
injections = list()
140-
injections.append(PoolFactory) # FIXME
141-
142-
for type_ in old:
143-
if not issubclass(type_, InjectableMixin):
144-
continue
145-
injections.append(type_)
131+
injections = [import_module(classname) for classname in injections]
146132

147133
# noinspection PyTypeChecker
148134
return injections
@@ -231,36 +217,7 @@ def _get_services(self) -> list[type]:
231217
return services
232218

233219
def _get_pools(self) -> dict[str, type]:
234-
try:
235-
pools = self.get_by_key("service.injections")
236-
except Exception:
237-
pools = list()
238-
239-
if isinstance(pools, dict):
240-
pools = list(pools.values())
241-
242-
old = [import_module(classname) for classname in pools]
243-
244-
from ..pools import (
245-
Pool,
246-
)
247-
248-
pools = dict()
249-
250-
for type_ in old:
251-
if not issubclass(type_, Pool):
252-
continue
253-
label = "unknown"
254-
if "lock" in type_.__name__.lower():
255-
label = "lock"
256-
elif "postgres" in type_.__name__.lower():
257-
label = "database"
258-
elif "broker" in type_.__name__.lower():
259-
label = "broker"
260-
261-
pools[label] = type_
262-
263-
return pools
220+
return dict()
264221

265222
def _get_routers(self) -> list[type]:
266223
try:

packages/core/minos-microservice-common/minos/common/config/v2.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,8 @@ def _get_injections(self) -> list[Union[InjectableMixin, type[InjectableMixin]]]
5050

5151
partial_ans = list()
5252

53-
from ..pools import (
54-
PoolFactory,
55-
)
56-
57-
partial_ans.append(PoolFactory) # FIXME
58-
5953
with suppress(MinosConfigException):
60-
partial_ans.extend(self._get_pools().values())
54+
partial_ans.append(self._get_pools().get("factory"))
6155

6256
with suppress(MinosConfigException):
6357
partial_ans.append(self._get_interfaces().get("http").get("connector"))
@@ -96,7 +90,7 @@ def _get_injections(self) -> list[Union[InjectableMixin, type[InjectableMixin]]]
9690
):
9791
type_ = builder_type
9892
elif not issubclass(type_, InjectableMixin):
99-
continue # raise MinosConfigException(f"{type_!r} must be subclass of {InjectableMixin!r}.")
93+
raise MinosConfigException(f"{type_!r} must be subclass of {InjectableMixin!r}.")
10094

10195
ans.append(type_)
10296

@@ -154,14 +148,22 @@ def _parse_periodic_interface(data: dict[str, Any]) -> dict[str, Any]:
154148
return data
155149

156150
def _get_pools(self) -> dict[str, type]:
151+
from ..pools import (
152+
PoolFactory,
153+
)
154+
factory = PoolFactory
155+
157156
try:
158-
data = self.get_by_key("pools")
157+
types = self.get_by_key("pools")
159158
except MinosConfigException:
160-
data = dict()
159+
types = dict()
161160

162-
data = {name: import_module(classname) for name, classname in data.items()}
161+
types = {name: import_module(classname) for name, classname in types.items()}
163162

164-
return data
163+
return {
164+
"factory": factory,
165+
"types": types,
166+
}
165167

166168
def _get_routers(self) -> list[type]:
167169
try:

packages/core/minos-microservice-common/minos/common/database/pools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
OperationalError,
2222
)
2323

24+
from ..injections import Injectable
2425
from ..locks import (
2526
LockPool,
2627
)
@@ -119,6 +120,7 @@ def acquire(self, key: Hashable, *args, **kwargs) -> DatabaseLock:
119120
return DatabaseLock(super().acquire(), key, *args, **kwargs)
120121

121122

123+
@Injectable("postgresql_pool")
122124
class PostgreSqlLockPool(DatabaseLockPool):
123125
"""TODO"""
124126

packages/core/minos-microservice-common/minos/common/locks.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
cached_property,
1717
)
1818

19+
from .injections import (
20+
Injectable,
21+
)
1922
from .pools import (
2023
Pool,
2124
)
@@ -43,5 +46,6 @@ def hashed_key(self) -> int:
4346
return self.key
4447

4548

49+
@Injectable("lock_pool")
4650
class LockPool(Pool[Lock], ABC):
4751
"""Postgres Locking Pool class."""

packages/core/minos-microservice-common/tests/test_common/test_config/test_v1/test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from minos.common import (
77
Config,
88
ConfigV1,
9-
MinosConfigException,
9+
MinosConfigException, PoolFactory,
1010
)
1111
from tests.utils import (
1212
BASE_PATH,

packages/core/minos-microservice-common/tests/test_common/test_config/test_v2/test_base.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import unittest
2-
from itertools import (
3-
chain,
4-
cycle,
5-
)
62
from unittest.mock import (
73
patch,
84
)
@@ -62,9 +58,6 @@ def test_name(self):
6258
def test_injections(self):
6359
expected = [
6460
PoolFactory,
65-
FakeLockPool,
66-
FakeDatabasePool,
67-
FakeBrokerClientPool,
6861
FakeHttpConnector,
6962
FakeBrokerPublisher,
7063
FakeBrokerSubscriberBuilder(FakeBrokerSubscriber),
@@ -82,8 +75,7 @@ def test_injections_not_defined(self): # FIXME
8275
self.assertEqual([PoolFactory], self.config.get_injections())
8376

8477
def test_injections_not_injectable(self):
85-
side_effect = chain([{"client": "builtins.int"}], cycle([MinosConfigException("")]))
86-
with patch.object(ConfigV2, "get_by_key", side_effect=side_effect):
78+
with patch.object(ConfigV2, "_get_pools", return_value={"factory": int}):
8779
with self.assertRaises(MinosConfigException):
8880
self.config.get_injections()
8981

@@ -147,15 +139,19 @@ def test_interface_unknown(self):
147139

148140
def test_pools(self):
149141
expected = {
150-
"broker": FakeBrokerClientPool,
151-
"database": FakeDatabasePool,
152-
"lock": FakeLockPool,
142+
"factory": PoolFactory,
143+
"types": {
144+
"broker": FakeBrokerClientPool,
145+
"database": FakeDatabasePool,
146+
"lock": FakeLockPool,
147+
}
153148
}
154149
self.assertEqual(expected, self.config.get_pools())
155150

156151
def test_pools_not_defined(self):
152+
expected = {"factory": PoolFactory, "types": {}}
157153
with patch.object(ConfigV2, "get_by_key", side_effect=MinosConfigException("")):
158-
self.assertEqual(dict(), self.config.get_pools())
154+
self.assertEqual(expected, self.config.get_pools())
159155

160156
def test_services(self):
161157
self.assertEqual([float, int], self.config.get_services())

packages/core/minos-microservice-common/tests/test_common/test_config/test_v2/test_parameterized.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,6 @@ def test_injections_nones(self):
3939

4040
expected = [
4141
PoolFactory,
42-
FakeLockPool,
43-
FakeDatabasePool,
44-
FakeBrokerClientPool,
4542
FakeBrokerPublisher,
4643
FakeBrokerSubscriberBuilder(FakeBrokerSubscriber),
4744
FakeEventRepository,

packages/core/minos-microservice-networks/minos/networks/brokers/pools.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414

1515
from minos.common import (
1616
Config,
17+
Injectable,
1718
Pool,
1819
)
1920

@@ -27,16 +28,12 @@
2728
logger = logging.getLogger(__name__)
2829

2930

31+
@Injectable("broker_pool")
3032
class BrokerClientPool(Pool):
3133
"""Broker Client Pool class."""
3234

3335
def __init__(
34-
self,
35-
instance_kwargs: dict[str, Any],
36-
maxsize: int = 5,
37-
recycle: Optional[int] = 3600,
38-
*args,
39-
**kwargs,
36+
self, instance_kwargs: dict[str, Any], maxsize: int = 5, recycle: Optional[int] = 3600, *args, **kwargs
4037
):
4138
super().__init__(maxsize=maxsize, recycle=recycle, *args, **kwargs)
4239
self._instance_kwargs = instance_kwargs

0 commit comments

Comments
 (0)