forked from ckan/ckan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1505fb6
commit 677f8af
Showing
15 changed files
with
289 additions
and
404 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
from ckan.lib.cli import load_config | ||
|
||
|
||
def pytest_addoption(parser): | ||
"""Allow using custom config file during tests. | ||
""" | ||
parser.addoption(u"--ckan-ini", action=u"store") | ||
|
||
|
||
def pytest_sessionstart(session): | ||
"""Initialize CKAN environment. | ||
""" | ||
load_config(session.config.option.ckan_ini) | ||
|
||
|
||
def pytest_runtest_setup(item): | ||
custom_config = [ | ||
mark.args for mark in item.iter_markers(name="ckan_config") | ||
] | ||
if custom_config: | ||
item.fixturenames.append('ckan_config') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
import ckan.plugins as plugins | ||
import ckan.plugins.toolkit as tk | ||
from ckan.common import config | ||
|
||
|
||
def test_ckan_config_fixture(ckan_config): | ||
assert tk.asbool(ckan_config[u"testing"]) | ||
|
||
|
||
def test_ckan_config_do_not_have_some_new_config(ckan_config): | ||
assert u"some.new.config" not in ckan_config | ||
|
||
|
||
@pytest.mark.ckan_config(u"some.new.config", u"exists") | ||
def test_ckan_config_mark(ckan_config): | ||
assert ckan_config[u"some.new.config"] == u"exists" | ||
|
||
|
||
@pytest.mark.ckan_config(u"some.new.config", u"exists") | ||
@pytest.mark.usefixtures(u"ckan_config") | ||
def test_ckan_config_mark_without_explicit_config_fixture(): | ||
assert config[u"some.new.config"] == u"exists" | ||
|
||
|
||
@pytest.mark.ckan_config(u"ckan.plugins", u"") | ||
@pytest.mark.usefixtures(u"with_plugins") | ||
def test_with_plugins_is_able_to_run_without_plugins(): | ||
assert not plugins.plugin_loaded(u"stats") | ||
|
||
|
||
@pytest.mark.ckan_config(u"ckan.plugins", u"stats") | ||
@pytest.mark.usefixtures(u"with_plugins") | ||
def test_with_plugins_is_able_to_run_with_stats(): | ||
assert plugins.plugin_loaded(u"stats") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,45 @@ | ||
# encoding: utf-8 | ||
|
||
import nose | ||
import pytest | ||
|
||
from ckan import authz as auth | ||
|
||
from ckan.tests import helpers | ||
_check = auth.check_config_permission | ||
|
||
|
||
assert_equals = nose.tools.assert_equals | ||
@pytest.mark.ckan_config("ckan.auth.anon_create_dataset", None) | ||
@pytest.mark.parametrize( | ||
"perm", ["anon_create_dataset", "ckan.auth.anon_create_dataset"] | ||
) | ||
def test_get_default_value_if_not_set_in_config(perm): | ||
assert _check(perm) == auth.CONFIG_PERMISSIONS_DEFAULTS["anon_create_dataset"] | ||
|
||
|
||
class TestCheckConfigPermission(object): | ||
@pytest.mark.ckan_config("ckan.auth.anon_create_dataset", True) | ||
def test_config_overrides_default(): | ||
assert _check("anon_create_dataset") is True | ||
|
||
@helpers.change_config('ckan.auth.anon_create_dataset', None) | ||
def test_get_default_value_if_not_set_in_config(self): | ||
|
||
assert_equals(auth.check_config_permission( | ||
'anon_create_dataset'), | ||
auth.CONFIG_PERMISSIONS_DEFAULTS['anon_create_dataset']) | ||
@pytest.mark.ckan_config("ckan.auth.anon_create_dataset", True) | ||
def test_config_override_also_works_with_prefix(): | ||
assert _check("ckan.auth.anon_create_dataset") is True | ||
|
||
@helpers.change_config('ckan.auth.anon_create_dataset', None) | ||
def test_get_default_value_also_works_with_prefix(self): | ||
|
||
assert_equals(auth.check_config_permission( | ||
'ckan.auth.anon_create_dataset'), | ||
auth.CONFIG_PERMISSIONS_DEFAULTS['anon_create_dataset']) | ||
@pytest.mark.ckan_config("ckan.auth.unknown_permission", True) | ||
def test_unknown_permission_returns_false(): | ||
assert _check("unknown_permission") is False | ||
|
||
@helpers.change_config('ckan.auth.anon_create_dataset', True) | ||
def test_config_overrides_default(self): | ||
|
||
assert_equals(auth.check_config_permission( | ||
'anon_create_dataset'), | ||
True) | ||
def test_unknown_permission_not_in_config_returns_false(): | ||
assert _check("unknown_permission") is False | ||
|
||
@helpers.change_config('ckan.auth.anon_create_dataset', True) | ||
def test_config_override_also_works_with_prefix(self): | ||
|
||
assert_equals(auth.check_config_permission( | ||
'ckan.auth.anon_create_dataset'), | ||
True) | ||
def test_default_roles_that_cascade_to_sub_groups_is_a_list(): | ||
assert isinstance(_check("roles_that_cascade_to_sub_groups"), list) | ||
|
||
@helpers.change_config('ckan.auth.unknown_permission', True) | ||
def test_unknown_permission_returns_false(self): | ||
|
||
assert_equals(auth.check_config_permission( | ||
'unknown_permission'), | ||
False) | ||
|
||
def test_unknown_permission_not_in_config_returns_false(self): | ||
|
||
assert_equals(auth.check_config_permission( | ||
'unknown_permission'), | ||
False) | ||
|
||
def test_default_roles_that_cascade_to_sub_groups_is_a_list(self): | ||
|
||
assert isinstance(auth.check_config_permission( | ||
'roles_that_cascade_to_sub_groups'), | ||
list) | ||
|
||
@helpers.change_config('ckan.auth.roles_that_cascade_to_sub_groups', | ||
'admin editor') | ||
def test_roles_that_cascade_to_sub_groups_is_a_list(self): | ||
|
||
assert_equals(sorted(auth.check_config_permission( | ||
'roles_that_cascade_to_sub_groups')), | ||
sorted(['admin', 'editor'])) | ||
@pytest.mark.ckan_config("ckan.auth.roles_that_cascade_to_sub_groups", "admin editor") | ||
def test_roles_that_cascade_to_sub_groups_is_a_list(): | ||
assert sorted(_check("roles_that_cascade_to_sub_groups")) == sorted( | ||
["admin", "editor"] | ||
) |
Oops, something went wrong.