示例#1
0
 def test_context_found_subscriber_wrong_id_name(self):
     config = DummyConfigurator()
     tweens.enable_selfalias(config, 'foo')
     context_found_subscriber = config.subscribed[0][0]
     request = Mock(user=Mock(username='******'), matchdict={'qoo': 'self'})
     context_found_subscriber(Mock(request=request))
     assert request.matchdict['qoo'] == 'self'
示例#2
0
 def test_context_found_subscriber_not_authenticated(self):
     config = DummyConfigurator()
     tweens.enable_selfalias(config, 'foo')
     context_found_subscriber = config.subscribed[0][0]
     request = Mock(user=None, matchdict={'foo': 'self'})
     context_found_subscriber(Mock(request=request))
     assert request.matchdict['foo'] == 'self'
示例#3
0
 def test_context_found_subscriber_no_matchdict(self):
     config = DummyConfigurator()
     tweens.enable_selfalias(config, 'foo')
     context_found_subscriber = config.subscribed[0][0]
     request = Mock(user=Mock(username='******'), matchdict=None)
     context_found_subscriber(Mock(request=request))
     assert request.matchdict is None
示例#4
0
 def test_enable_selfalias(self):
     from pyramid.events import ContextFound
     config = DummyConfigurator()
     assert config.subscribed == []
     tweens.enable_selfalias(config, 'foo')
     assert len(config.subscribed) == 1
     assert six.callable(config.subscribed[0][0])
     assert config.subscribed[0][1] is ContextFound
示例#5
0
 def test_enable_selfalias(self):
     from pyramid.events import ContextFound
     config = DummyConfigurator()
     assert config.subscribed == []
     tweens.enable_selfalias(config, 'foo')
     assert len(config.subscribed) == 1
     assert six.callable(config.subscribed[0][0])
     assert config.subscribed[0][1] is ContextFound
示例#6
0
 def test_context_found_subscriber_wrong_id_name(self):
     config = DummyConfigurator()
     tweens.enable_selfalias(config, 'foo')
     context_found_subscriber = config.subscribed[0][0]
     request = Mock(
         user=Mock(username='******'),
         matchdict={'qoo': 'self'})
     context_found_subscriber(Mock(request=request))
     assert request.matchdict['qoo'] == 'self'
示例#7
0
 def test_context_found_subscriber_not_authenticated(self):
     config = DummyConfigurator()
     tweens.enable_selfalias(config, 'foo')
     context_found_subscriber = config.subscribed[0][0]
     request = Mock(
         user=None,
         matchdict={'foo': 'self'})
     context_found_subscriber(Mock(request=request))
     assert request.matchdict['foo'] == 'self'
示例#8
0
 def test_context_found_subscriber_no_matchdict(self):
     config = DummyConfigurator()
     tweens.enable_selfalias(config, 'foo')
     context_found_subscriber = config.subscribed[0][0]
     request = Mock(
         user=Mock(username='******'),
         matchdict=None)
     context_found_subscriber(Mock(request=request))
     assert request.matchdict is None
示例#9
0
def bootstrap(config):
    Settings.update(config.registry.settings)
    Settings[APP_NAME + '.__version__'] = __version__
    Settings[nefertari.APP_NAME+'.__version__'] = nefertari.__version__

    config.include('nefertari')

    root = config.get_root_resource()
    root.auth = Settings.asbool('auth')
    root.default_factory = 'nefertari.acl.AdminACL'

    config.include('example_api.model')
    config.include('nefertari.view')
    config.include('nefertari.elasticsearch')

    enable_selfalias(config, "username")

    if Settings.asbool('debug'):
        log.warning('*** DEBUG DEBUG DEBUG mode ***')
        config.add_tween('nefertari.tweens.get_tunneling')

    if Settings.asbool('cors.enable'):
        config.add_tween('nefertari.tweens.cors')

    if Settings.asbool('ssl_middleware.enable'):
        config.add_tween('nefertari.tweens.ssl')

    if Settings.asbool('request_timing.enable'):
        config.add_tween('nefertari.tweens.request_timing')

    if Settings.asbool('auth', False):
        config.add_request_method(
            'example_api.model.User.get_authuser_by_userid', 'user', reify=True)
    else:
        log.warning('*** USER AUTHENTICATION IS DISABLED ! ***')
        config.add_request_method(
            'example_api.model.User.get_unauth_user', 'user', reify=True)

    def _route_url(request, route_name, *args, **kw):
        if config.route_prefix:
            route_name = '%s_%s' % (config.route_prefix, route_name)
        return request.route_url(route_name, *args, **kw)

    config.add_request_method(_route_url)

    def _route_path(request, route_name, *args, **kw):
        if config.route_prefix:
            route_name = '%s_%s' % (config.route_prefix, route_name)
        return request.route_path(route_name, *args, **kw)

    config.add_request_method(_route_path)