From d533ac110a3b13928a83fc4245e17ad2411aa86f Mon Sep 17 00:00:00 2001 From: Roman Mogylatov Date: Thu, 21 Jan 2021 11:28:42 -0500 Subject: [PATCH] Add extra tests for asynchronous injections --- docs/main/changelog.rst | 1 + tests/unit/providers/test_async_py36.py | 45 +++++++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/docs/main/changelog.rst b/docs/main/changelog.rst index dc01d074..b876a03b 100644 --- a/docs/main/changelog.rst +++ b/docs/main/changelog.rst @@ -13,6 +13,7 @@ follows `Semantic versioning`_ See issue: `#368 `_. Thanks `@kolypto `_ for the bug report. - Refactor asynchronous injections. +- Add extra tests for asynchronous injections. 4.10.3 ------ diff --git a/tests/unit/providers/test_async_py36.py b/tests/unit/providers/test_async_py36.py index 812fcc6b..6b58664e 100644 --- a/tests/unit/providers/test_async_py36.py +++ b/tests/unit/providers/test_async_py36.py @@ -236,6 +236,51 @@ class FactoryTests(AsyncTestCase): self.assertIsNot(service1.client, service2.client) + def test_async_instance_and_sync_attributes_injection(self): + class ContainerWithAttributes(containers.DeclarativeContainer): + resource1 = providers.Resource(init_resource, providers.Object(RESOURCE1)) + + client = providers.Factory( + Client, + resource1, + resource2=None, + ) + client.add_attributes(resource2=providers.Object(RESOURCE2)) + + service = providers.Factory( + Service, + client=None, + ) + service.add_attributes(client=client) + + container = ContainerWithAttributes() + + client1 = self._run(container.client()) + client2 = self._run(container.client()) + + self.assertIsInstance(client1, Client) + self.assertIs(client1.resource1, RESOURCE1) + self.assertIs(client1.resource2, RESOURCE2) + + self.assertIsInstance(client2, Client) + self.assertIs(client2.resource1, RESOURCE1) + self.assertIs(client2.resource2, RESOURCE2) + + service1 = self._run(container.service()) + service2 = self._run(container.service()) + + self.assertIsInstance(service1, Service) + self.assertIsInstance(service1.client, Client) + self.assertIs(service1.client.resource1, RESOURCE1) + self.assertIs(service1.client.resource2, RESOURCE2) + + self.assertIsInstance(service2, Service) + self.assertIsInstance(service2.client, Client) + self.assertIs(service2.client.resource1, RESOURCE1) + self.assertIs(service2.client.resource2, RESOURCE2) + + self.assertIsNot(service1.client, service2.client) + class FactoryAggregateTests(AsyncTestCase):