Exemplo n.º 1
0
 def test_ensure_key_name_as_string(self):
     container = Container()
     self.assertEqual(container.ensure_key_string(Foo),
                      'test.test_container.Foo')
     self.assertEqual(container.ensure_key_string("key"), 'key')
     self.assertEqual(container.ensure_key_string(1), '1')
     self.assertEqual(container.ensure_key_string(2.5), '2.5')
Exemplo n.º 2
0
 def test_register_instance_using_class_types(self):
     container = Container()
     container.instance(Foo, Foo())
     container.instance(FooBar, FooBar())
     self.assertIsInstance(container.make('test.test_container.Foo'), Foo)
     self.assertIsInstance(container.make('test.test_container.FooBar'),
                           FooBar)
Exemplo n.º 3
0
 def test_bind_for_class_name_with_arguments(self):
     container = Container()
     self.assertIsInstance(
         container.make('test.test_container.Dummy', {
             "client_id": "1",
             "key": "QWERTY1"
         }), Dummy)
Exemplo n.º 4
0
 def test_register_singleton_using_class_types(self):
     container = Container()
     container.singleton(Foo, Foo())
     container.singleton(FooBar, FooBar())
     self.assertEqual(container.make('test.test_container.Foo'),
                      container.make('test.test_container.Foo'))
     self.assertEqual(container.make('test.test_container.FooBar'),
                      container.make('test.test_container.FooBar'))
Exemplo n.º 5
0
 def test_singleton_instance(self):
     container = Container()
     container.singleton('singleton', 'test.test_container.Foo')
     container.singleton('singleton2', 'test.test_container.FooBar')
     self.assertEqual(container.make('singleton'),
                      container.make('singleton'))
     self.assertEqual(container.make('singleton2'),
                      container.make('singleton2'))
Exemplo n.º 6
0
 def test_add_route_with_delete_verb(self):
     container = Container()
     router = Router(container)
     router.delete('/home', 'test@test')
     routes = router.get_routes()
     self.assertEqual(routes['DELETE/home'], {
         'method': 'DELETE',
         'uri': '/home',
         'action': {
             'uses': 'test@test'
         }
     })
Exemplo n.º 7
0
 def test_add_route_with_put_verb(self):
     container = Container()
     router = Router(container)
     router.put('/home', 'test@test')
     routes = router.get_routes()
     self.assertEqual(routes['PUT/home'], {
         'method': 'PUT',
         'uri': '/home',
         'action': {
             'uses': 'test@test',
         }
     })
Exemplo n.º 8
0
 def test_add_route(self):
     container = Container()
     router = Router(container)
     router.add_route('GET', '/home', 'test@test')
     routes = router.get_routes()
     self.assertEqual(routes['GET/home'], {
         'method': 'GET',
         'uri': '/home',
         'action': {
             'uses': 'test@test'
         }
     })
Exemplo n.º 9
0
 def test_add_route_with_head_verb(self):
     container = Container()
     router = Router(container)
     router.head('/home', 'test@test')
     routes = router.get_routes()
     self.assertEqual(routes['HEAD/home'], {
         'method': 'HEAD',
         'uri': '/home',
         'action': {
             'uses': 'test@test'
         }
     })
Exemplo n.º 10
0
 def test_add_route_with_options_verb(self):
     container = Container()
     router = Router(container)
     router.options('/home', 'test@test')
     routes = router.get_routes()
     self.assertEqual(routes['OPTIONS/home'], {
         'method': 'OPTIONS',
         'uri': '/home',
         'action': {
             'uses': 'test@test'
         }
     })
Exemplo n.º 11
0
 def test_add_route_with_multiple_verbs(self):
     container = Container()
     router = Router(container)
     router.add_route(['GET', 'POST'], '/home', 'test@test')
     routes = router.get_routes()
     self.assertEqual(routes['GET/home'], {
         'method': 'GET',
         'uri': '/home',
         'action': {
             'uses': 'test@test'
         }
     })
     self.assertEqual(routes['POST/home'], {
         'method': 'POST',
         'uri': '/home',
         'action': {
             'uses': 'test@test'
         }
     })
Exemplo n.º 12
0
 def test_bind_for_class_name_with_default_arguments(self):
     container = Container()
     self.assertIsInstance(
         container.make('test.test_container.Defaults', {"client_id": "1"}),
         Defaults)
Exemplo n.º 13
0
 def test_bind_for_class_name_with_dependencies(self):
     container = Container()
     container.bind('key', 'test.test_container.Baz')
     self.assertIsInstance(container.make('key'), Baz)
Exemplo n.º 14
0
 def test_bind_for_class_name(self):
     container = Container()
     container.bind('key', 'test.test_container.Foo')
     self.assertIsInstance(container.make('key'), Foo)
Exemplo n.º 15
0
 def test_import_class(self):
     self.assertEqual(Container.import_class('test.test_container.Foo'),
                      Foo)
Exemplo n.º 16
0
 def test_bind_instance(self):
     container = Container()
     mock = Foo()
     container.instance('key', mock)
     self.assertEqual(mock, container.make('key'))
Exemplo n.º 17
0
    def test_add_group_routes(self):
        container = Container()
        router = Router(container)

        # Using group decorator
        @router.group({
            "middleware": "auth",
            'before': 'auth',
            'namespace': 'admin',
            'domain': '{account}.myapp.com',
            'prefix': 'admin'
        })
        def group(_router):
            _router.get('/home', {'as': 'home', 'uses': 'CMSController@home'})
            _router.post('/about', 'CMSController@about')

            @router.group({
                "middleware": "auth",
                'before': 'auth',
                'namespace': 'users.',
                'domain': '{account}.myapp.com',
                'prefix': 'users'
            })
            def _group(_router):
                _router.get(
                    '/', {
                        'as': 'users',
                        'uses': 'UserController@index',
                        'middleware': 'permissions'
                    })
                _router.get('/{id}', 'UserController@show')

        routes = router.get_routes()
        self.assertEqual(
            routes['GET/admin/home'], {
                'method': 'GET',
                'uri': '/admin/home',
                'action': {
                    'as': 'home',
                    'uses': 'admin.CMSController@home',
                    'middleware': ['auth']
                }
            })
        self.assertEqual(
            routes['POST/admin/about'], {
                'method': 'POST',
                'uri': '/admin/about',
                'action': {
                    'uses': 'admin.CMSController@about',
                    'middleware': ['auth']
                }
            })
        self.assertEqual(
            routes['GET/admin/users'], {
                'method': 'GET',
                'uri': '/admin/users',
                'action': {
                    'as': 'users',
                    'uses': 'admin.users.UserController@index',
                    'middleware': ['auth', 'permissions']
                }
            })
        self.assertEqual(
            routes['GET/admin/users/{id}'], {
                'method': 'GET',
                'uri': '/admin/users/{id}',
                'action': {
                    'uses': 'admin.users.UserController@show',
                    'middleware': ['auth']
                }
            })
Exemplo n.º 18
0
 def test_add_route_with_alias(self):
     container = Container()
     router = Router(container)
     router.add_route('GET', '/home', {'as': 'home', 'uses': 'test@test'})
     routes = router.named_routes
     self.assertEqual(routes['home'], '/home')
Exemplo n.º 19
0
 def app():
     return Container()
Exemplo n.º 20
0
 def test_bind_from_lambda(self):
     container = Container()
     container.bind('key', lambda cont: 'Object')
     self.assertEqual('Object', container.make('key'))