Пример #1
0
 def _create_child_routes(self, definition, parent_route):
     children = definition.get('children', ())
     for child in children:
         if isinstance(child, str):
             name, child = child, children[child]
         else:
             name = child['name']
         child['requires'] = dict_deep_update(child.get('requires', {}), parent_route.requires)
         child['defaults'] = dict_deep_update(child.get('defaults', {}), parent_route.requires)
         name = '{0}/{1}'.format(parent_route.name, name)
         if 'path' not in child:
             child['path'] = '/{}'.format(name)
         child['path'] = '{0}{1}'.format(parent_route.path, child['path'])
         child['name'] = name
         self.add_definition(child)
 def test_complex_deep(self):
     d1 = {
         'a': {
             'b': {
                 'key': [
                     'a',
                     'b',
                     'c',
                     'd',
                 ]
             }
         }
     }
     d2 = {
         'a': {
             'b': {
                 'key': [
                     'e',
                     'f',
                     'g',
                 ]
             }
         }
     }
     merged = dict_deep_update(d1, d2)
     assert 'c' in merged['a']['b']['key']
Пример #3
0
    def register_components(self):
        """Register any components specified with the application.

        Components can include the following modules:
            - dependencies
            - events
            - models
            - routes
            - views

        Registering a component will merge any configuration settings within
        the above modules prior to the application booting.

        An example component might look like:

        /component
            /views
                /index.html
            /routes.py
            /views.py
        """
        types = ('dependencies', 'events', 'routes', 'models', 'views')
        for component in self.config['components']:
            for type_ in types:
                with contextmanagers.suppress(Exception):
                    type_component = imports.load_definition_from_string(
                        '{}.{}.{}'.format(component, type_, type_))
                    if type_ == 'dependencies':
                        self.container.update(type_component)
                    if not isinstance(type_component, ModuleType):
                        self._config[type_] = dict_deep_update(
                            self._config.get(type_, {}), type_component)
            self._config['views'][
                'renderers']['jinja2']['config']['packages'].append(
                (component, 'views'))
Пример #4
0
 def __init__(self, config=None, argv=None):
     super(Console, self).__init__(config)
     self.config = dict_deep_update({
         'commands': find_commands_in_module(DefaultConsoleCommands)
     }, self.config)
     self.runner = Runner(argv, commands=self.config.get('commands'))
     self.runner.get_command = self.get_command
 def test_complex_deep(self):
     d1 = {
         'a': {
             'b': {
                 'key': [
                     'a',
                     'b',
                     'c',
                     'd',
                 ]
             }
         }
     }
     d2 = {
         'a': {
             'b': {
                 'key': [
                     'e',
                     'f',
                     'g',
                 ]
             }
         }
     }
     merged = dict_deep_update(d1, d2)
     assert 'c' in merged['a']['b']['key']
Пример #6
0
 def __init__(self, config=None, argv=None):
     super(Console, self).__init__(config)
     self.config = dict_deep_update(
         {'commands': find_commands_in_module(DefaultConsoleCommands)},
         self.config)
     self.runner = Runner(argv, commands=self.config.get('commands'))
     self.runner.get_command = self.get_command
Пример #7
0
 def update_config(self, app):
     app.config['auth'] = datastructures.dict_deep_update(
         config.defaults, app.config.get('auth', {}))
     app.container.get('app_exception_listener').templates.update(
         config.templates)
     self.container.get('jinja2_renderer').add_package_loader(
         'watson.auth', 'views')
Пример #8
0
 def _setup_provider(self, app, provider, config_):
     auth_config = app.config['auth']
     provider_ = imports.load_definition_from_string(provider)
     provider_config = datastructures.dict_deep_update(
         auth_config['common'], provider_.defaults)
     provider_config = datastructures.dict_deep_update(
         provider_config, config_)
     config_.update(provider_config)
     dependency_config = {
         'init': {
             'config': lambda container: container.get('application.config')['auth']['providers'][provider],
             'session': lambda container: container.get('sqlalchemy_session_{0}'.format(container.get('application.config')['auth']['providers'][provider]['session'])),
         }
     }
     dependency_config.update(app.config['dependencies'][
                                 'definitions'].get(provider, {}))
     app.container.add_definition(provider, dependency_config)
Пример #9
0
    def __init__(self, config=None):
        """Initializes the container and set some default configuration options.

        Args:
            dict config: A dict containing the params, definitions and processors.
        """
        self.config = dict_deep_update(DEFAULTS, config or {})
        self.__instantiated = {}
        for event, listeners in self.config['processors'].items():
            for processor in listeners:
                self.attach_processor(event, load_definition_from_string(processor)())
Пример #10
0
    def __init__(self, config=None):
        """Initializes the container and set some default configuration options.

        Args:
            dict config: A dict containing the params, definitions and processors.
        """
        self.config = dict_deep_update(DEFAULTS, config or {})
        self.__instantiated = {}
        for event, listeners in self.config['processors'].items():
            for processor in listeners:
                self.attach_processor(event,
                                      load_definition_from_string(processor)())
Пример #11
0
    def __init__(self, config=None):
        """Initializes the container and set some default configuration options.

        Args:
            config (dict): The params, definitions and processors.
        """
        self.__instantiated__ = {}
        self.config = dict_deep_update(DEFAULTS, config or {})
        self.__instantiated__ = {}
        self._pre_process_event = types.Event(name=PRE_EVENT)
        self._post_process_event = types.Event(name=POST_EVENT)
        for event, listeners in self.config['processors'].items():
            for processor in listeners:
                self.attach_processor(
                    event,
                    imports.load_definition_from_string(processor)())
Пример #12
0
    def config(self, config):
        """Sets the configuration for the application.

        Usage:
            app = Base()
            app.config = {'some': 'settings'}

        Args:
            mixed config: The configuration to use.
        """
        if isinstance(config, ModuleType):
            conf = module_to_dict(config, '__')
        else:
            conf = config or {}
        self._config = dict_deep_update(module_to_dict(DefaultConfig, '__'), conf)
        self.container.add('application.config', self.config)
Пример #13
0
    def config(self, config):
        """Sets the configuration for the application.

        Usage:
            app = Base()
            app.config = {'some': 'settings'}

        Args:
            mixed config: The configuration to use.
        """
        if isinstance(config, ModuleType):
            conf = module_to_dict(config, '__')
        else:
            conf = config or {}
        self._config = dict_deep_update(module_to_dict(DefaultConfig, '__'),
                                        conf)
        self.container.add('application.config', self.config)
 def test_deepcopy_invalid_copy(self):
     pattern = re.compile('test')
     d = {'re': pattern}
     new_dict = dict_deep_update(d, {'test': 'testing'})
     assert 'test' in new_dict
     assert new_dict['re'] is pattern
Пример #15
0
 def test_dict_deep_update(self):
     d1 = {'a': {'b': 3}}
     d2 = {'a': {'b': 4}}
     merged = dict_deep_update(d1, d2)
     assert merged['a']['b'] == 4
 def test_dict_deep_update_not_dict(self):
     d1 = {'a': {'b': 3}}
     d2 = 'b'
     merged = dict_deep_update(d1, d2)
     assert merged == 'b'
Пример #17
0
 def test_dict_deep_update_not_dict(self):
     d1 = {'a': {'b': 3}}
     d2 = 'b'
     merged = dict_deep_update(d1, d2)
     assert merged == 'b'
 def test_deepcopy_invalid_copy(self):
     pattern = re.compile('test')
     d = {'re': pattern}
     new_dict = dict_deep_update(d, {'test': 'testing'})
     assert 'test' in new_dict
     assert new_dict['re'] is pattern
Пример #19
0
 def setup_config(self):
     auth_config = datastructures.dict_deep_update(
         config.defaults, self.app_config.get('auth', {}))
     self.app_config['auth'] = auth_config
 def test_dict_deep_update(self):
     d1 = {'a': {'b': 3}}
     d2 = {'a': {'b': 4}}
     merged = dict_deep_update(d1, d2)
     assert merged['a']['b'] == 4
Пример #21
0
 def setup_authenticator(self):
     dependency_config = datastructures.dict_deep_update(
         config.definitions['auth_authenticator'], self.app_config['dependencies']['definitions'].get('auth_authenticator', {}))
     self.app_config['dependencies']['definitions']['auth_authenticator'] = dependency_config
     self.container.definitions['auth_authenticator'] = dependency_config
Пример #22
0
            'class': 'tests.watson.auth.support.MockMailBackend'
        }
    },
}

# Initialize a sample application
app = applications.Http(app_config)
request = Request.from_environ(
    sample_environ(), session_class='watson.http.sessions.Memory')

default_provider_settings = dict_deep_update(
    config.defaults['common'],
    {
        'model': {
            'class': 'tests.watson.auth.support.TestUser'
        },
        'secret': 'APP_SECRET',
        'algorithm': 'HS256',
        'system_email_from_address': '*****@*****.**',
        'reset_password_route': 'auth/reset-password',
        'forgotten_password_route': 'auth/forgotten-password'
    })


class MockMailBackend(object):
    def send(self, message, **kwargs):
        pass


class TestSampleForm(object):
    field_one = None
    field_two = None