Skip to content

Commit 00691f5

Browse files
author
Sergio García Prado
committed
ISSUE #346
* Increase coverage.
1 parent 9a31859 commit 00691f5

File tree

2 files changed

+47
-16
lines changed

2 files changed

+47
-16
lines changed

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

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import unittest
2-
import warnings
32
from abc import (
43
ABC,
54
)
5+
from contextlib import (
6+
suppress,
7+
)
68
from itertools import (
79
starmap,
810
)
@@ -11,6 +13,7 @@
1113
)
1214
from typing import (
1315
Any,
16+
Union,
1417
)
1518
from uuid import (
1619
uuid4,
@@ -26,6 +29,7 @@
2629
)
2730
from .injections import (
2831
DependencyInjector,
32+
InjectableMixin,
2933
)
3034
from .pools import (
3135
PoolFactory,
@@ -42,37 +46,32 @@ def setUp(self) -> None:
4246
self.injector = DependencyInjector(self.config, self.get_injections())
4347
self.injector.wire_injections()
4448

45-
def get_config(self):
46-
""" "TODO"""
49+
def get_config(self) -> Config:
4750
return Config(self.get_config_file_path())
4851

4952
def get_config_file_path(self) -> Path:
50-
"""TODO"""
51-
warnings.warn(
52-
"`CONFIG_FILE_PATH` variable has been deprecated by `get_config_file_path` method",
53-
DeprecationWarning,
54-
)
5553
return self.CONFIG_FILE_PATH
5654

57-
def get_injections(self):
55+
def get_injections(self) -> list[Union[InjectableMixin, type[InjectableMixin], str]]:
5856
return []
5957

60-
async def asyncSetUp(self):
58+
async def asyncSetUp(self) -> None:
6159
await super().asyncSetUp()
6260
await self.injector.setup_injections()
6361

64-
async def asyncTearDown(self):
62+
async def asyncTearDown(self) -> None:
6563
await self.injector.destroy_injections()
6664
await super().asyncTearDown()
6765

6866
def tearDown(self) -> None:
6967
self.injector.unwire_injections()
7068
super().tearDown()
7169

72-
def __getattr__(self, item):
70+
def __getattr__(self, item: str) -> Any:
7371
if item != "injector":
74-
return getattr(self.injector, item)
75-
raise AttributeError
72+
with suppress(Exception):
73+
return getattr(self.injector, item)
74+
raise AttributeError(f"{type(self).__name__!r} does not contain the {item!r} attribute.")
7675

7776

7877
class PostgresAsyncTestCase(MinosTestCase, ABC):
@@ -95,7 +94,7 @@ def setUp(self):
9594

9695
super().setUp()
9796

98-
def get_config(self):
97+
def get_config(self) -> Config:
9998
return Config(
10099
self.get_config_file_path(),
101100
repository_database=self.repository_db["database"],
@@ -106,7 +105,7 @@ def get_config(self):
106105
snapshot_user=self.snapshot_db["user"],
107106
)
108107

109-
def get_injections(self):
108+
def get_injections(self) -> list[Union[InjectableMixin, type[InjectableMixin], str]]:
110109
return [PoolFactory.from_config(self.config, default_classes={"database": DatabaseClientPool})]
111110

112111
async def asyncSetUp(self):
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import unittest
2+
3+
from minos.common import (
4+
Config,
5+
DependencyInjector,
6+
)
7+
from minos.common.testing import (
8+
MinosTestCase,
9+
)
10+
from tests.utils import (
11+
CONFIG_FILE_PATH,
12+
)
13+
14+
15+
class MyMinosTestCase(MinosTestCase):
16+
CONFIG_FILE_PATH = CONFIG_FILE_PATH
17+
18+
19+
class TestMinosTestCase(unittest.IsolatedAsyncioTestCase):
20+
def test_config(self):
21+
test_case = MyMinosTestCase()
22+
test_case.setUp()
23+
self.assertIsInstance(test_case.config, Config)
24+
25+
def test_injector(self):
26+
test_case = MyMinosTestCase()
27+
test_case.setUp()
28+
self.assertIsInstance(test_case.injector, DependencyInjector)
29+
30+
31+
if __name__ == "__main__":
32+
unittest.main()

0 commit comments

Comments
 (0)