Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[logic/converters] Add converter for tag string to tag with vocab
- Loading branch information
1 parent
2227d51
commit a411b14
Showing
2 changed files
with
52 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from ckan import model | ||
from ckan.logic.converters import convert_to_tags | ||
from ckan.lib.navl.dictization_functions import unflatten | ||
|
||
class TestConverters: | ||
def test_convert_to_tags(self): | ||
def convert(tag_string, vocab): | ||
key = 'vocab_tag_string' | ||
data = {key: tag_string} | ||
errors = [] | ||
context = {'model': model, 'session': model.Session} | ||
convert_to_tags('vocab')(key, data, errors, context) | ||
del data[key] | ||
return data | ||
|
||
data = unflatten(convert('tag1, tag2', 'vocab')) | ||
for tag in data['tags']: | ||
assert tag['name'] in ['tag1', 'tag2'] | ||
assert tag['vocabulary'] == 'vocab' | ||
|