def test_make_safe_no_effect(self): decl = Declaration() decl.declare(Key().a, 10) cfg = CKANConfig() assert not decl.make_safe(cfg) assert cfg == CKANConfig()
def test_normalize_no_effect(self): decl = Declaration() decl.declare_int(Key().a, "10") cfg = CKANConfig() assert not decl.normalize(cfg) assert cfg == CKANConfig()
def test_subset_works(): conf = CKANConfig({ "a.b": 1, "a.c": 2, "x.b": 3, }) assert conf.subset(Key().a.dynamic("any")) == {"a.b": 1, "a.c": 2}
def test_make_safe_no_overrides(self): decl = Declaration() decl.declare(Key().a, 10) cfg = CKANConfig({"config.mode": "strict", "a": 20}) assert decl.make_safe(cfg) assert cfg == CKANConfig({"config.mode": "strict", "a": 20})
def test_make_safe_in_safe_mode(self): decl = Declaration() decl.declare(Key().a, 10) cfg = CKANConfig({"config.mode": "strict"}) assert decl.make_safe(cfg) assert cfg == CKANConfig({"config.mode": "strict", "a": 10})
def test_keys_works(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' my_conf[u'test_key_2'] = u'Test value 2' eq_(sorted(my_conf.keys()), [u'test_key_1', u'test_key_2'])
def get_formats(config: CKANConfig) -> dict[str, list[str]]: out = {} out["text_formats"] = config.get_value("ckan.preview.text_formats").split() out["xml_formats"] = config.get_value("ckan.preview.xml_formats").split() out["json_formats"] = config.get_value("ckan.preview.json_formats").split() out["jsonp_formats"] = config.get_value( "ckan.preview.jsonp_formats").split() return out
def test_iteritems_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" my_conf[u"test_key_2"] = u"Test value 2" cnt = 0 for key, value in my_conf.items(): cnt += 1 assert key.startswith(u"test_key_") assert value.startswith(u"Test value") assert cnt == 2
def test_normalize_in_normalized_mode(self): decl = Declaration() decl.declare_int(Key().a, "10") cfg = CKANConfig({"config.mode": "strict"}) assert decl.normalize(cfg) # in non-safe mode default value has no effect assert cfg == CKANConfig({"config.mode": "strict"}) cfg = CKANConfig({"config.mode": "strict", "a": "10"}) assert decl.normalize(cfg) assert cfg == CKANConfig({"config.mode": "strict", "a": 10})
def test_iteritems_works(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' my_conf[u'test_key_2'] = u'Test value 2' cnt = 0 for key, value in my_conf.iteritems(): cnt += 1 assert key.startswith(u'test_key_') assert value.startswith(u'Test value') eq_(cnt, 2)
def add_ckan_admin_tab(config_: CKANConfig, route_name: str, tab_label: str, config_var: str = "ckan.admin_tabs", icon: Optional[str] = None): """ Update 'ckan.admin_tabs' dict the passed config dict. """ # get the admin_tabs dict from the config, or an empty dict. admin_tabs_dict = config_.get(config_var, {}) # update the admin_tabs dict with the new values admin_tabs_dict.update({route_name: {"label": tab_label, "icon": icon}}) # update the config with the updated admin_tabs dict config_.update({config_var: admin_tabs_dict})
def test_true_if_not_empty(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' assert my_conf
def test_repr_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" if six.PY3: assert repr(my_conf) == u"{'test_key_1': 'Test value 1'}" else: assert repr(my_conf) == u"{u'test_key_1': u'Test value 1'}"
def update_config(self, config: CKANConfig): DatastoreBackend.register_backends() DatastoreBackend.set_active_backend(config) templates_base = config.get_value('ckan.base_templates_folder') p.toolkit.add_template_directory(config, templates_base) self.backend = DatastoreBackend.get_active_backend()
def test_del_works(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' del my_conf[u'test_key_1'] assert u'test_key_1' not in my_conf
def test_len_works(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' my_conf[u'test_key_2'] = u'Test value 2' eq_(len(my_conf), 2)
def update_config(self, config: CKANConfig): u''' Set up the resource library, public directory and template directory for the view ''' # https://datatables.net/reference/option/lengthMenu self.page_length_choices = config.get_value( u'ckan.datatables.page_length_choices') self.page_length_choices = [int(i) for i in self.page_length_choices] self.state_saving = config.get_value(u'ckan.datatables.state_saving') # https://datatables.net/reference/option/stateDuration self.state_duration = config.get_value( u"ckan.datatables.state_duration") self.data_dictionary_labels = config.get_value( u"ckan.datatables.data_dictionary_labels") self.ellipsis_length = config.get_value( u"ckan.datatables.ellipsis_length") self.date_format = config.get_value(u"ckan.datatables.date_format") self.default_view = config.get_value(u"ckan.datatables.default_view") toolkit.add_template_directory(config, u'templates') toolkit.add_public_directory(config, u'public') toolkit.add_resource(u'public', u'ckanext-datatablesview')
def test_for_in_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" my_conf[u"test_key_2"] = u"Test value 2" cnt = 0 for key in my_conf: cnt += 1 assert key.startswith(u"test_key_") assert cnt == 2
def test_clear_works(self): # Keep a copy of the original Pylons config _original_pylons_config = pylons.config.copy() my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' my_conf[u'test_key_2'] = u'Test value 2' eq_(len(my_conf.keys()), 2) my_conf.clear() eq_(len(my_conf.keys()), 0) # Restore Pylons config pylons.config.update(_original_pylons_config)
def _add_served_directory(config_: CKANConfig, relative_path: str, config_var: str): """Add extra public/template directories to config.""" import inspect import os assert config_var in ("extra_template_paths", "extra_public_paths") # we want the filename that of the function caller but they will # have used one of the available helper functions filename = inspect.stack()[2].filename this_dir = os.path.dirname(filename) absolute_path = os.path.join(this_dir, relative_path) if absolute_path not in config_.get_value(config_var).split(","): if config_.get_value(config_var): config_[config_var] += "," + absolute_path else: config_[config_var] = absolute_path return absolute_path
def configure(self, config: CKANConfig): self.config = config for config_option in ( u'ckan.site_url', u'ckan.datapusher.url', ): if not config.get_value(config_option): raise Exception( u'Config option `{0}` must be set to use the DataPusher.'. format(config_option))
def test_for_in_works(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' my_conf[u'test_key_2'] = u'Test value 2' cnt = 0 for key in my_conf: cnt += 1 assert key.startswith(u'test_key_') eq_(cnt, 2)
def test_clear_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" my_conf[u"test_key_2"] = u"Test value 2" assert len(my_conf.keys()) == 2 my_conf.clear() assert len(my_conf.keys()) == 0
def test_clear_works(): # Keep a copy of the original Pylons config _original_pylons_config = pylons.config.copy() my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" my_conf[u"test_key_2"] = u"Test value 2" assert len(my_conf.keys()) == 2 my_conf.clear() assert len(my_conf.keys()) == 0 # Restore Pylons config pylons.config.update(_original_pylons_config)
def test_get_item_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" assert my_conf.get(u"test_key_1") == u"Test value 1"
def test_get_item_works(self): my_conf = CKANConfig() my_conf[u'test_key_1'] = u'Test value 1' eq_(my_conf.get(u'test_key_1'), u'Test value 1')
def test_true_if_not_empty(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" assert my_conf
def test_not_true_if_empty(): my_conf = CKANConfig() assert not my_conf
def test_keys_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" my_conf[u"test_key_2"] = u"Test value 2" assert sorted(my_conf.keys()) == [u"test_key_1", u"test_key_2"]
def test_len_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" my_conf[u"test_key_2"] = u"Test value 2" assert len(my_conf) == 2
def test_repr_works(): my_conf = CKANConfig() my_conf[u"test_key_1"] = u"Test value 1" assert repr(my_conf) == u"{'test_key_1': 'Test value 1'}"