• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

qld-gov-au / ckan / ffdd3d13-9fd2-42d6-8817-f9a076d0bad6

21 Jan 2026 02:47AM UTC coverage: 79.551% (-8.3%) from 87.869%
ffdd3d13-9fd2-42d6-8817-f9a076d0bad6

Pull #239

circleci

ThrawnCA
[QOLSVC-12515] add support for specifying facet sorts via query parameters

- Use '_{facet}_sort' as a parallel to '_{facet}_limit', with comma separation for the ordering, eg
'_tags_sort=count,desc' to mimic the default popularity-based sorting.
Pull Request #239: QOLSVC-12515 alphabetical facet sort

11 of 35 new or added lines in 2 files covered. (31.43%)

13656 existing lines in 309 files now uncovered.

42766 of 53759 relevant lines covered (79.55%)

1.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

89.58
/ckan/tests/cli/test_cli.py
1
# -*- coding: utf-8 -*-
2

3
from configparser import InterpolationMissingOptionError
3✔
4
import pytest
3✔
5
import os
3✔
6

7
from ckan.cli.cli import ckan
3✔
8
from ckan.cli import CKANConfigLoader
3✔
9
from ckan.exceptions import CkanConfigurationException
3✔
10

11

12
def test_without_args(cli):
3✔
13
    """Show help by default.
14
    """
UNCOV
15
    result = cli.invoke(ckan)
1✔
UNCOV
16
    assert u'Usage: ckan' in result.output
1✔
UNCOV
17
    assert not result.exit_code, result.output
1✔
18

19

20
def test_incorrect_config(cli):
3✔
21
    """Config file must exist.
22
    """
UNCOV
23
    result = cli.invoke(ckan, [u'-c', u'/a/b/c/d/e/f/g/h.ini'])
×
UNCOV
24
    assert result.output.startswith(u'Config file not found')
×
25

26

27
def test_correct_config(cli, ckan_config):
3✔
28
    """With explicit config file user still sees help message.
29
    """
30
    result = cli.invoke(ckan, [u'-c', ckan_config[u'__file__']])
1✔
31
    assert u'Usage: ckan' in result.output
1✔
32
    assert not result.exit_code, result.output
1✔
33

34

35
def test_correct_config_with_help(cli, ckan_config):
3✔
36
    """Config file not ignored when displaying usage.
37
    """
UNCOV
38
    result = cli.invoke(ckan, [u'-c', ckan_config[u'__file__'], u'-h'])
×
UNCOV
39
    assert not result.exit_code, result.output
×
40

41

42
def test_config_via_env_var(cli, ckan_config):
3✔
43
    """CliRunner uses test config automatically, so we have to explicitly
44
    set CLI `-c` option to `None` when using env `CKAN_INI`.
45

46
    """
UNCOV
47
    result = cli.invoke(ckan, [u'-c', None, u'-h'],
×
48
                        env={u'CKAN_INI': ckan_config[u'__file__']})
UNCOV
49
    assert not result.exit_code, result.output
×
50

51

52
@pytest.mark.ckan_config(u'ckan.plugins', u'example_iclick')
3✔
53
@pytest.mark.usefixtures(u'with_plugins', u'with_extended_cli')
3✔
54
def test_command_from_extension_shown_in_help_when_enabled(cli):
3✔
55
    """Extra commands shown in help when plugin enabled.
56
    """
UNCOV
57
    result = cli.invoke(ckan, [])
1✔
UNCOV
58
    assert u'example-iclick-hello' in result.output
1✔
59

UNCOV
60
    result = cli.invoke(ckan, [u'--help'])
1✔
UNCOV
61
    assert u'example-iclick-hello' in result.output
1✔
62

63

64
def test_ckan_config_loader_parse_file():
3✔
65
    """
66
    CKANConfigLoader should parse and interpolate variables in
67
    test-core.ini.tpl file both in DEFAULT and app:main section.
68
    """
69
    tpl_dir = os.path.dirname(__file__) + u'/templates'
1✔
70
    filename = os.path.join(tpl_dir, u'test-core.ini.tpl')
1✔
71
    conf = CKANConfigLoader(filename).get_config()
1✔
72

73
    assert conf[u'debug'] == u'false'
1✔
74

75
    assert conf[u'key1'] == tpl_dir + u'/core'
1✔
76
    assert conf[u'key2'] == tpl_dir + u'/core'
1✔
77
    assert conf[u'key4'] == u'core'
1✔
78

79
    assert conf[u'__file__'] == filename
1✔
80

81
    with pytest.raises(KeyError):
1✔
82
        conf[u'host']
1✔
83

84
    assert conf['here'] == tpl_dir
1✔
85

86

87
def test_ckan_config_loader_parse_two_files():
3✔
88
    """
89
    CKANConfigLoader should parse both 'test-extension.ini.tpl' and
90
    'test-core.ini.tpl' and override the values of 'test-core.ini.tpl' with
91
    the values of test-extension.ini.tpl.
92

93
    Values in [DEFAULT] section are always override.
94
    """
95
    tpl_dir = os.path.dirname(__file__) + u'/templates'
1✔
96
    extension_tpl_dir = tpl_dir + u'/ckanext-extension'
1✔
97
    filename = os.path.join(extension_tpl_dir, u'test-extension.ini.tpl')
1✔
98
    conf = CKANConfigLoader(filename).get_config()
1✔
99

100
    # Debug should not be overridden by lower-level config test-core.ini.tpl
101
    assert conf[u'debug'] == u'true'
1✔
102
    # __file__ should never be override if parsing two files
103
    assert conf[u'__file__'] == filename
1✔
104

105
    assert conf[u'key1'] == extension_tpl_dir + u'/extension'
1✔
106
    assert conf[u'key2'] == tpl_dir + u'/core'
1✔
107
    assert conf[u'key3'] == extension_tpl_dir + u'/extension'
1✔
108
    assert conf[u'key4'] == u'extension'
1✔
109

110
    with pytest.raises(KeyError):
1✔
111
        conf[u'host']
1✔
112

113
    assert conf[u'here'] == extension_tpl_dir
1✔
114

115

116
def test_ckan_env_vars_in_config(monkeypatch):
3✔
117
    """CKAN_ prefixed environment variables can be used in config.
118
    """
UNCOV
119
    filename = os.path.join(
1✔
120
        os.path.dirname(__file__), u'data', u'test-env-var.ini')
UNCOV
121
    monkeypatch.setenv("CKAN_TEST_ENV_VAR", "value")
1✔
UNCOV
122
    conf = CKANConfigLoader(filename).get_config()
1✔
UNCOV
123
    assert conf["var"] == "value"
1✔
124

125

126
def test_other_env_vars_ignored(monkeypatch):
3✔
127
    """Non-CKAN_ environment variables are ignored
128
    """
UNCOV
129
    filename = os.path.join(
×
130
        os.path.dirname(__file__), u'data', u'test-no-env-var.ini')
UNCOV
131
    monkeypatch.setenv("TEST_ENV_VAR", "value")
×
UNCOV
132
    with pytest.raises(InterpolationMissingOptionError):
×
UNCOV
133
        CKANConfigLoader(filename).get_config()
×
134

135

136
def test_chain_loading():
3✔
137
    """Load chains of config files via `use = config:...`.
138
    """
UNCOV
139
    filename = os.path.join(
1✔
140
        os.path.dirname(__file__), u'data', u'test-one.ini')
UNCOV
141
    conf = CKANConfigLoader(filename).get_config()
1✔
UNCOV
142
    assert conf[u'__file__'] == filename
1✔
UNCOV
143
    assert conf[u'key1'] == u'one'
1✔
UNCOV
144
    assert conf[u'key2'] == u'two'
1✔
UNCOV
145
    assert conf[u'key3'] == u'three'
1✔
146

147

148
def test_recursive_loading():
3✔
149
    """ Make sure we still remember main config file.
150

151
    If there are circular dependencies, make sure the user knows about it.
152
    """
153
    filename = os.path.join(
1✔
154
        os.path.dirname(__file__), u'data', u'test-one-recursive.ini')
155
    with pytest.raises(CkanConfigurationException):
1✔
156
        CKANConfigLoader(filename).get_config()
1✔
157

158

159
def test_variables_in_chained_files():
3✔
160
    """Variables are available across all files in chain.
161

162
    When variables got redefined latest version is used, just as in python's
163
    class-inheritance. The only exception is the `here` variable, which
164
    evaluated immediately.
165
    """
166
    here = os.path.dirname(__file__)
1✔
167
    filename = os.path.join(
1✔
168
        here, u'data', u'test-one.ini')
169
    conf = CKANConfigLoader(filename).get_config()
1✔
170
    assert conf["one.from2"] == "2"
1✔
171
    assert conf["one.from3"] == "3"
1✔
172

173
    assert conf["two.from3"] == "3"
1✔
174

175
    assert conf["parts"] == "one two three"
1✔
176

177
    assert conf["here.one"] == os.path.join(here, "data")
1✔
178
    assert conf["here.two"] == os.path.join(here, "data", "sub")
1✔
179
    assert conf["here.three"] == os.path.join(here, "data")
1✔
180

181

182
def test_invalid_use_option():
3✔
183
    """Report missing colon in `use` value
184
    """
UNCOV
185
    filename = os.path.join(
1✔
186
        os.path.dirname(__file__), u'data', u'test-invalid-use.ini')
UNCOV
187
    with pytest.raises(CkanConfigurationException):
1✔
UNCOV
188
        CKANConfigLoader(filename).get_config()
1✔
189

190

191
def test_reference_to_non_existing_config():
3✔
192
    """Report missing file in the config chain.
193
    """
UNCOV
194
    filename = os.path.join(
1✔
195
        os.path.dirname(__file__), u'data', u'test-non-existing-path.ini')
UNCOV
196
    with pytest.raises(CkanConfigurationException):
1✔
UNCOV
197
        CKANConfigLoader(filename).get_config()
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc