From c8fda3da8dc1b75b98d4ad57d2a7f014bdb63715 Mon Sep 17 00:00:00 2001 From: Roman Mogilatov Date: Sun, 28 Feb 2016 17:50:47 +0200 Subject: [PATCH] Add FactoryAsDecoratorTests --- tests/test_providers.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/test_providers.py b/tests/test_providers.py index 82761606..93fabcae 100644 --- a/tests/test_providers.py +++ b/tests/test_providers.py @@ -1089,3 +1089,27 @@ class ConfigTests(unittest.TestCase): 'ChildConfig({0}) at {1}>'.format( repr('.'.join(('category', 'setting'))), hex(id(category_setting)))) + + +class FactoryAsDecoratorTests(unittest.TestCase): + """Factory as decorator tests.""" + + def test_decoration(self): + """Test decoration of some class with Factory provider.""" + @providers.Factory + class AuthService(object): + """Auth service.""" + + @providers.Factory + @injections.inject(auth_service=AuthService) + class UsersService(object): + """Users service.""" + + def __init__(self, auth_service): + """Initializer.""" + self.auth_service = auth_service + + users_service = UsersService() + + self.assertIsInstance(users_service, UsersService.cls) + self.assertIsInstance(users_service.auth_service, AuthService.cls)