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')
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)
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)
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'))
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'))
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' } })
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', } })
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' } })
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' } })
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' } })
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' } })
def test_bind_for_class_name_with_default_arguments(self): container = Container() self.assertIsInstance( container.make('test.test_container.Defaults', {"client_id": "1"}), Defaults)
def test_bind_for_class_name_with_dependencies(self): container = Container() container.bind('key', 'test.test_container.Baz') self.assertIsInstance(container.make('key'), Baz)
def test_bind_for_class_name(self): container = Container() container.bind('key', 'test.test_container.Foo') self.assertIsInstance(container.make('key'), Foo)
def test_import_class(self): self.assertEqual(Container.import_class('test.test_container.Foo'), Foo)
def test_bind_instance(self): container = Container() mock = Foo() container.instance('key', mock) self.assertEqual(mock, container.make('key'))
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'] } })
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')
def app(): return Container()
def test_bind_from_lambda(self): container = Container() container.bind('key', lambda cont: 'Object') self.assertEqual('Object', container.make('key'))