Skip to content

Commit 4a85647

Browse files
author
Sergio García Prado
committed
ISSUE #?
* Fix warnings.
1 parent 8153427 commit 4a85647

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

packages/core/minos-microservice-common/tests/test_common/test_database/test_mixins.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,25 @@
2020

2121
# noinspection SqlNoDataSourceInspection,SqlResolve
2222
class TestDatabaseMixin(CommonTestCase, DatabaseMinosTestCase):
23-
def test_constructor(self):
24-
pool = DatabaseClientPool.from_config(self.config)
25-
# noinspection PyTypeChecker
26-
database = DatabaseMixin(pool)
27-
self.assertEqual(pool, database.database_pool)
23+
async def test_constructor(self):
24+
async with DatabaseClientPool.from_config(self.config) as pool:
25+
# noinspection PyTypeChecker
26+
database = DatabaseMixin(pool)
27+
self.assertEqual(pool, database.database_pool)
2828

2929
async def test_constructor_with_pool_factory(self):
30-
pool_factory = PoolFactory(self.config, {"database": DatabaseClientPool})
31-
# noinspection PyTypeChecker
32-
database = DatabaseMixin(pool_factory=pool_factory)
33-
# noinspection PyUnresolvedReferences
34-
self.assertEqual(pool_factory.get_pool("database"), database.database_pool)
30+
async with PoolFactory(self.config, {"database": DatabaseClientPool}) as pool_factory:
31+
# noinspection PyTypeChecker
32+
database = DatabaseMixin(pool_factory=pool_factory)
33+
# noinspection PyUnresolvedReferences
34+
self.assertEqual(pool_factory.get_pool("database"), database.database_pool)
3535

3636
async def test_constructor_with_pool_factory_and_database_key(self):
37-
pool_factory = PoolFactory(self.config, {"database": DatabaseClientPool})
38-
# noinspection PyTypeChecker
39-
database = DatabaseMixin(pool_factory=pool_factory, database_key=("query", "unknown"))
40-
# noinspection PyUnresolvedReferences
41-
self.assertEqual(pool_factory.get_pool("database", "query"), database.database_pool)
37+
async with PoolFactory(self.config, {"database": DatabaseClientPool}) as pool_factory:
38+
# noinspection PyTypeChecker
39+
database = DatabaseMixin(pool_factory=pool_factory, database_key=("query", "unknown"))
40+
# noinspection PyUnresolvedReferences
41+
self.assertEqual(pool_factory.get_pool("database", "query"), database.database_pool)
4242

4343
async def test_constructor_raises(self):
4444
with self.assertRaises(NotProvidedException):

packages/core/minos-microservice-common/tests/test_common/test_database/test_pools.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ def setUp(self) -> None:
2828
super().setUp()
2929
self.pool = DatabaseClientPool.from_config(self.config)
3030

31-
def test_constructor(self):
31+
async def test_constructor(self):
3232
builder = DatabaseClientBuilder()
33-
pool = DatabaseClientPool(builder)
34-
self.assertEqual(builder, pool.client_builder)
33+
async with DatabaseClientPool(builder) as pool:
34+
self.assertEqual(builder, pool.client_builder)
3535

3636
async def asyncSetUp(self):
3737
await super().asyncSetUp()
@@ -41,15 +41,15 @@ async def asyncTearDown(self):
4141
await self.pool.destroy()
4242
await super().asyncTearDown()
4343

44-
def test_from_config(self):
45-
pool = DatabaseClientPool.from_config(self.config, key="event")
46-
self.assertIsInstance(pool.client_builder, DatabaseClientBuilder)
47-
self.assertEqual(MockedDatabaseClient, pool.client_builder.instance_cls)
44+
async def test_from_config(self):
45+
async with DatabaseClientPool.from_config(self.config, key="event") as pool:
46+
self.assertIsInstance(pool.client_builder, DatabaseClientBuilder)
47+
self.assertEqual(MockedDatabaseClient, pool.client_builder.instance_cls)
4848

49-
def test_from_config_client_builder(self):
49+
async def test_from_config_client_builder(self):
5050
config = Config(CONFIG_FILE_PATH, databases_default_client=classname(DatabaseClientBuilder))
51-
pool = DatabaseClientPool.from_config(config)
52-
self.assertIsInstance(pool.client_builder, DatabaseClientBuilder)
51+
async with DatabaseClientPool.from_config(config) as pool:
52+
self.assertIsInstance(pool.client_builder, DatabaseClientBuilder)
5353

5454
def test_from_config_client_none(self):
5555
config = Config(CONFIG_FILE_PATH, databases_default_client=None)

packages/core/minos-microservice-common/tests/test_common/test_pools.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,18 @@ def setUp(self):
3636
super().setUp()
3737
self.factory = PoolFactory(self.config, {"lock": FakeLockPool})
3838

39-
def test_from_config(self):
40-
self.assertIsInstance(PoolFactory.from_config(self.config), PoolFactory)
39+
async def asyncSetUp(self):
40+
await super().asyncSetUp()
41+
await self.factory.setup()
4142

4243
async def asyncTearDown(self):
4344
await self.factory.destroy()
4445
await super().asyncTearDown()
4546

47+
async def test_from_config(self):
48+
async with PoolFactory.from_config(self.config) as pool_factory:
49+
self.assertIsInstance(pool_factory, PoolFactory)
50+
4651
def test_get_pool(self):
4752
lock = self.factory.get_pool("lock")
4853
self.assertIsInstance(lock, FakeLockPool)
@@ -119,11 +124,11 @@ class TestMinosPool(unittest.IsolatedAsyncioTestCase):
119124
def test_is_subclass(self):
120125
self.assertTrue(issubclass(MinosPool, SetupMixin))
121126

122-
def test_warnings(self):
127+
async def test_warnings(self):
123128
with warnings.catch_warnings():
124129
warnings.simplefilter("ignore", DeprecationWarning)
125-
setup = _MinosPool()
126-
self.assertIsInstance(setup, SetupMixin)
130+
async with _MinosPool() as setup:
131+
self.assertIsInstance(setup, SetupMixin)
127132

128133

129134
class _MinosPool(MinosPool):

packages/core/minos-microservice-cqrs/tests/test_cqrs/test_services.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ def setUp(self) -> None:
4646

4747
self.service = FakeService(config=self.config, lock_pool=self.lock_pool)
4848

49+
async def asyncSetUp(self):
50+
await super().asyncSetUp()
51+
await self.lock_pool.setup()
52+
53+
async def asyncTearDown(self) -> None:
54+
await self.lock_pool.destroy()
55+
await super().asyncTearDown()
56+
4957
def tearDown(self) -> None:
5058
self.injector.unwire_injections()
5159
super().tearDown()

packages/core/minos-microservice-networks/tests/utils.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,24 @@
5050
class NetworksTestCase(MinosTestCase, ABC):
5151
testing_module = testing
5252

53+
def setUp(self) -> None:
54+
self.lock_pool = FakeLockPool()
55+
super().setUp()
56+
57+
async def asyncSetUp(self) -> None:
58+
await self.lock_pool.setup()
59+
await super().asyncSetUp()
60+
61+
async def asyncTearDown(self) -> None:
62+
await super().asyncTearDown()
63+
await self.lock_pool.destroy()
64+
5365
def get_config_file_path(self):
5466
return CONFIG_FILE_PATH
5567

5668
def get_injections(self) -> list[Union[InjectableMixin, type[InjectableMixin], str]]:
5769
injections = [
58-
InMemoryTransactionRepository(lock_pool=FakeLockPool()),
70+
InMemoryTransactionRepository(lock_pool=self.lock_pool),
5971
]
6072
# noinspection PyTypeChecker
6173
return super().get_injections() + injections

0 commit comments

Comments
 (0)