Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '1841-ivalidators-iconverters'
- Loading branch information
Showing
14 changed files
with
275 additions
and
34 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 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 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 |
---|---|---|
@@ -1,7 +1,4 @@ | ||
from ckan.plugins.core import * | ||
from ckan.plugins.interfaces import * | ||
|
||
# Expose the toolkit object without doing an import * | ||
import toolkit as _toolkit | ||
toolkit = _toolkit.toolkit | ||
del _toolkit | ||
import toolkit |
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
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,30 @@ | ||
from ckan.plugins.toolkit import Invalid | ||
from ckan import plugins | ||
|
||
|
||
class ExampleIValidatorsPlugin(plugins.SingletonPlugin): | ||
plugins.implements(plugins.IValidators) | ||
|
||
def get_validators(self): | ||
return { | ||
'equals_fortytwo': equals_fortytwo, | ||
} | ||
|
||
|
||
class ExampleIConvertersPlugin(plugins.SingletonPlugin): | ||
plugins.implements(plugins.IConverters) | ||
|
||
def get_converters(self): | ||
return { | ||
'negate': negate, | ||
} | ||
|
||
|
||
def equals_fortytwo(value): | ||
if value != 42: | ||
raise Invalid('not 42') | ||
return value | ||
|
||
|
||
def negate(value): | ||
return -value |
Empty file.
40 changes: 40 additions & 0 deletions
40
ckanext/example_ivalidators_iconverters/tests/test_ivalidators_iconverters.py
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,40 @@ | ||
from nose.tools import assert_equals, assert_raises | ||
import pylons.config as config | ||
|
||
from ckan.plugins.toolkit import get_validator, get_converter, Invalid | ||
from ckan.logic import clear_converters_cache, clear_validators_cache | ||
from ckan import plugins | ||
|
||
|
||
class TestIValidators(object): | ||
@classmethod | ||
def setup_class(cls): | ||
plugins.load('example_ivalidators') | ||
clear_validators_cache() | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
plugins.unload('example_ivalidators') | ||
|
||
def test_custom_validator_validates(self): | ||
v = get_validator('equals_fortytwo') | ||
assert_raises(Invalid, v, 41) | ||
|
||
def test_custom_validator_passes(self): | ||
v = get_validator('equals_fortytwo') | ||
assert_equals(v(42), 42) | ||
|
||
|
||
class TestIConverters(object): | ||
@classmethod | ||
def setup_class(cls): | ||
plugins.load('example_iconverters') | ||
clear_converters_cache() | ||
|
||
@classmethod | ||
def teardown_class(cls): | ||
plugins.unload('example_iconverters') | ||
|
||
def test_custom_converter_converts(self): | ||
c = get_converter('negate') | ||
assert_equals(c(19), -19) |
Oops, something went wrong.