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
Showing
5 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
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,45 @@ | ||
# -*- coding: utf-8 -*- | ||
import ckan.plugins as p | ||
from ckan.plugins.toolkit import (auth_allow_anonymous_access, | ||
chained_auth_function, | ||
chained_action, | ||
side_effect_free, | ||
chained_helper | ||
) | ||
|
||
|
||
class ChainedFunctionsPlugin(p.SingletonPlugin): | ||
p.implements(p.IAuthFunctions) | ||
p.implements(p.IActions) | ||
p.implements(p.ITemplateHelpers) | ||
|
||
def get_auth_functions(self): | ||
return { | ||
"user_show": user_show | ||
} | ||
|
||
def get_actions(self): | ||
return { | ||
"package_search": package_search | ||
} | ||
|
||
def get_helpers(self): | ||
return { | ||
"ckan_version": ckan_version | ||
} | ||
|
||
@chained_auth_function | ||
@auth_allow_anonymous_access | ||
def user_show(next_auth, context, data_dict=None): | ||
return next_auth(context, data_dict) | ||
|
||
@chained_action | ||
@side_effect_free | ||
def package_search(original_action, context, data_dict): | ||
return original_action(context, data_dict) | ||
|
||
@chained_helper | ||
def ckan_version(next_func, **kw): | ||
return next_func(**kw) | ||
|
||
setattr(ckan_version, "some_attribute", "some_value") |
Empty file.
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,21 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
import pytest | ||
|
||
@pytest.mark.ckan_config(u"ckan.plugins", u"chained_functions") | ||
@pytest.mark.usefixtures(u"with_plugins") | ||
class TestChainedFunctionsPlugin(object): | ||
def test_auth_attributes_are_retained(self): | ||
from ckan.authz import _AuthFunctions | ||
user_show = _AuthFunctions.get("user_show") | ||
assert hasattr(user_show, 'auth_allow_anonymous_access') == True | ||
|
||
def test_action_attributes_are_retained(self): | ||
from ckan.plugins.toolkit import get_action | ||
package_search = get_action('package_search') | ||
assert hasattr(package_search, 'side_effect_free') == True | ||
|
||
def test_helper_attributes_are_retained(self): | ||
from ckan.lib.helpers import helper_functions | ||
ckan_version = helper_functions.get('ckan_version') | ||
assert hasattr(ckan_version, "some_attribute") == True |
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