コード例 #1
0
    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()
コード例 #2
0
    def test_normalize_no_effect(self):
        decl = Declaration()
        decl.declare_int(Key().a, "10")

        cfg = CKANConfig()
        assert not decl.normalize(cfg)
        assert cfg == CKANConfig()
コード例 #3
0
ファイル: test_common.py プロジェクト: kowh-ai/ckan
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}
コード例 #4
0
    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})
コード例 #5
0
    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})
コード例 #6
0
ファイル: test_common.py プロジェクト: CIOIL/DataGovIL
    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'])
コード例 #7
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    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'])
コード例 #8
0
ファイル: plugin.py プロジェクト: tino097/ckan
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
コード例 #9
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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
コード例 #10
0
    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})
コード例 #11
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    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)
コード例 #12
0
ファイル: test_common.py プロジェクト: CIOIL/DataGovIL
    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)
コード例 #13
0
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})
コード例 #14
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    def test_true_if_not_empty(self):

        my_conf = CKANConfig()

        my_conf[u'test_key_1'] = u'Test value 1'

        assert my_conf
コード例 #15
0
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'}"
コード例 #16
0
ファイル: plugin.py プロジェクト: tino097/ckan
    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()
コード例 #17
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    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
コード例 #18
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    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)
コード例 #19
0
ファイル: plugin.py プロジェクト: tino097/ckan
    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')
コード例 #20
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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
コード例 #21
0
ファイル: test_common.py プロジェクト: CIOIL/DataGovIL
    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)
コード例 #22
0
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
コード例 #23
0
ファイル: plugin.py プロジェクト: tino097/ckan
    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))
コード例 #24
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    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)
コード例 #25
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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
コード例 #26
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)
コード例 #27
0
ファイル: test_common.py プロジェクト: espona/ckan-1
    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)
コード例 #28
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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"
コード例 #29
0
ファイル: test_common.py プロジェクト: CIOIL/DataGovIL
    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')
コード例 #30
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
def test_true_if_not_empty():
    my_conf = CKANConfig()
    my_conf[u"test_key_1"] = u"Test value 1"
    assert my_conf
コード例 #31
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
def test_not_true_if_empty():
    my_conf = CKANConfig()
    assert not my_conf
コード例 #32
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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"]
コード例 #33
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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
コード例 #34
0
ファイル: test_common.py プロジェクト: paulmueller/ckan
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'}"