def load_registry(self): if self.enabled and self.registryLoaded is False: # Load the registry here not in configuration, # because the configuration are not load in order of score self.registryLoaded = True BlokManager.load() load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(self.AnyBlokOptions, ('bloks',)) db_name = Configuration.get('db_name') if not db_name: raise Exception("No database defined to run Test") registry = RegistryManager.get(db_name) if registry: installed_bloks = registry.System.Blok.list_by_state( "installed") selected_bloks = Configuration.get('selected_bloks') if not selected_bloks: selected_bloks = installed_bloks unwanted_bloks = Configuration.get('unwanted_bloks') if unwanted_bloks is None: unwanted_bloks = [] self.bloks_path = [BlokManager.getPath(x) for x in BlokManager.ordered_bloks] self.authoried_bloks_test_files = [ path for blok in installed_bloks if blok in selected_bloks and blok not in unwanted_bloks for path in [join(BlokManager.getPath(blok), 'tests')] if exists(path)] registry.close() # free the registry to force create it again
def init(self, parser, opts, args): Configuration.parse_options(opts, ('gunicorn',)) # get the configuration save in AnyBlok configuration in # gunicorn configuration for name in Configuration.configuration.keys(): if name in self.cfg.settings: value = Configuration.get(name) if value: self.cfg.settings[name].set(value)
def init(self, parser, opts, args): Configuration.parse_options(opts, ('gunicorn', )) # get the configuration save in AnyBlok configuration in # gunicorn configuration for name in Configuration.configuration.keys(): if name in self.cfg.settings: value = Configuration.get(name) if value: self.cfg.settings[name].set(value)
def test_parse_option_configuration(self): args = MockArgParseArguments(configfile="mock_configuration_file.cfg") Configuration.parse_options(args, ()) self.assertConfig({ 'db_name': 'anyblok', 'db_driver_name': 'postgres', 'db_user_name': '', 'db_password': '', 'db_host': 'localhost', 'db_port': '', 'configfile': 'mock_configuration_file.cfg', })
def test_parse_option_configuration(self): args = MockArgParseArguments(configfile="mock_configuration_file.cfg") Configuration.parse_options(args) self.assertConfig({ 'db_name': 'anyblok', 'db_driver_name': 'postgres', 'db_user_name': '', 'db_password': '', 'db_host': 'localhost', 'db_port': '', 'configfile': 'mock_configuration_file.cfg', })
def test_parse_option(self): kwargs = {'test': 'value'} args = MockArgParseArguments(configfile="mock_configuration_file.cfg", kwargs=kwargs) Configuration.parse_options(args) kwargs.update({ 'db_name': 'anyblok', 'db_driver_name': 'postgres', 'db_user_name': '', 'db_password': '', 'db_host': 'localhost', 'db_port': '', }) self.assertConfig(kwargs)
def test_parse_option(self): kwargs = {'test': 'value'} args = MockArgParseArguments(configfile="mock_configuration_file.cfg", kwargs=kwargs) Configuration.parse_options(args, ()) kwargs.update({ 'db_name': 'anyblok', 'db_driver_name': 'postgres', 'db_user_name': '', 'db_password': '', 'db_host': 'localhost', 'db_port': '', }) self.assertConfig(kwargs)
def load_registry(self): if not self.enabled or self.registryLoaded: return from anyblok.config import Configuration, get_db_name from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) from anyblok.blok import BlokManager from anyblok.registry import RegistryManager, return_list # Load the registry here not in configuration, # because the configurations are not loaded in order of score self.registryLoaded = True load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(self.AnyBlokOptions) configuration_post_load() BlokManager.load() db_name = get_db_name() registry = RegistryManager.get(db_name) if not registry: return installed_bloks = registry.System.Blok.list_by_state("installed") selected_bloks = return_list( Configuration.get('selected_bloks')) or installed_bloks unwanted_bloks = return_list(Configuration.get('unwanted_bloks')) or [] self.authorized_blok_paths = set( BlokManager.getPath(b) for b in BlokManager.list() if b in selected_bloks and b not in unwanted_bloks) test_dirs = self.authorized_blok_test_dirs = set() for startpath in self.authorized_blok_paths: for root, dirs, _ in walk(startpath): if 'tests' in dirs: test_dirs.add(join(root, 'tests')) registry.close() # free the registry to force create it again
def load_registry(self): if self.enabled and self.registryLoaded is False: # Load the registry here not in configuration, # because the configuration are not load in order of score self.registryLoaded = True load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(self.AnyBlokOptions) configuration_post_load() BlokManager.load() db_name = get_db_name() registry = RegistryManager.get(db_name) if registry: installed_bloks = registry.System.Blok.list_by_state( "installed") selected_bloks = return_list( Configuration.get('selected_bloks')) or installed_bloks unwanted_bloks = return_list( Configuration.get('unwanted_bloks')) or [] self.bloks_path = [BlokManager.getPath(x) for x in BlokManager.ordered_bloks] self.authoried_bloks_test_files = [] for blok in installed_bloks: if blok not in selected_bloks or blok in unwanted_bloks: continue startpath = BlokManager.getPath(blok) for root, dirs, _ in walk(startpath): if 'tests' in dirs: self.authoried_bloks_test_files.append( join(root, 'tests')) registry.close() # free the registry to force create it again
def test_parse_option_args(self): args = ('test',) args = MockArgParseArguments(args=args) with self.assertRaises(ConfigurationException): Configuration.parse_options(args, ['AnyBlok'])
def test_parse_option_kwargs(self): kwargs = {'test': 'value'} args = MockArgParseArguments(kwargs=kwargs) Configuration.parse_options(args) self.assertConfig(kwargs)
# # Copyright (C) 2015 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2017 Jean-Sebastien SUZANNE <*****@*****.**> # Copyright (C) 2018 Jean-Sebastien SUZANNE <*****@*****.**> # # This Source Code Form is subject to the terms of the Mozilla Public License, # v. 2.0. If a copy of the MPL was not distributed with this file,You can # obtain one at http://mozilla.org/MPL/2.0/. from anyblok.config import Configuration from anyblok import ( load_init_function_from_entry_points, configuration_post_load, ) load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() class MockParser: def _get_kwargs(self): return [] def _get_args(self): return False Configuration.parse_options(MockParser()) configuration_post_load(unittest=True)
def test_parse_option_kwargs(self): kwargs = {'test': 'value'} args = MockArgParseArguments(kwargs=kwargs) Configuration.parse_options(args, ['AnyBlok']) self.assertConfig(kwargs)
def load_configuration(): load_init_function_from_entry_points(unittest=True) Configuration.load_config_for_test() Configuration.parse_options(MockParser()) configuration_post_load(unittest=True)
def test_empty_parse_option(self): args = MockArgParseArguments() Configuration.parse_options(args, ['AnyBlok']) self.assertEqual(Configuration.configuration, {})
def test_empty_parse_option(self): args = MockArgParseArguments() Configuration.parse_options(args) self.assertEqual(Configuration.configuration, {})
def test_parse_option_args(self): args = ('test', ) args = MockArgParseArguments(args=args) with self.assertRaises(ConfigurationException): Configuration.parse_options(args)
def test_empty_parse_option(self): args = MockArgParseArguments() Configuration.parse_options(args) assert Configuration.configuration == {}