Skip to content

Commit

Permalink
[#2175] Validate package_show when using a custom schema.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Read committed Dec 30, 2014
1 parent 9a1b810 commit 8efa0ce
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
8 changes: 4 additions & 4 deletions ckan/logic/action/get.py
Expand Up @@ -977,10 +977,10 @@ def package_show(context, data_dict):
schema = context['schema']
else:
schema = package_plugin.show_package_schema()
if schema and context.get('validate', True):
package_dict, errors = lib_plugins.plugin_validate(
package_plugin, context, package_dict, schema,
'package_show')
if schema and context.get('validate', True):
package_dict, errors = lib_plugins.plugin_validate(
package_plugin, context, package_dict, schema,
'package_show')

for item in plugins.PluginImplementations(plugins.IPackageController):
item.after_show(context, package_dict)
Expand Down
23 changes: 23 additions & 0 deletions ckan/new_tests/logic/action/test_get.py
Expand Up @@ -17,6 +17,29 @@ def setup(self):
# Clear the search index
search.clear()

def test_package_show(self):
dataset1 = factories.Dataset()

dataset2 = helpers.call_action('package_show', id=dataset1['id'])

eq(dataset2['name'], dataset1['name'])
missing_keys = set(('title', 'groups')) - set(dataset2.keys())
assert not missing_keys, missing_keys

def test_package_show_with_custom_schema(self):
dataset1 = factories.Dataset()
from ckan.logic.schema import default_show_package_schema
custom_schema = default_show_package_schema()

def foo(key, data, errors, context):
data[key] = 'foo'
custom_schema['new_field'] = [foo]

dataset2 = helpers.call_action('package_show', id=dataset1['id'],
context={'schema': custom_schema})

eq(dataset2['new_field'], 'foo')

def test_group_list(self):

group1 = factories.Group()
Expand Down
12 changes: 0 additions & 12 deletions ckan/tests/logic/test_action.py
Expand Up @@ -114,18 +114,6 @@ def test_01_package_list_private(self):
assert 'public_dataset' in res
assert not 'private_dataset' in res

def test_01_package_show(self):
anna_id = model.Package.by_name(u'annakarenina').id
postparams = '%s=1' % json.dumps({'id': anna_id})
res = self.app.post('/api/action/package_show', params=postparams)
res_dict = json.loads(res.body)
assert_equal(res_dict['success'], True)
assert "/api/3/action/help_show?name=package_show" in res_dict['help']
pkg = res_dict['result']
assert_equal(pkg['name'], 'annakarenina')
missing_keys = set(('title', 'groups')) - set(pkg.keys())
assert not missing_keys, missing_keys

def test_01_package_show_with_jsonp(self):
anna_id = model.Package.by_name(u'annakarenina').id
postparams = '%s=1' % json.dumps({'id': anna_id})
Expand Down

0 comments on commit 8efa0ce

Please sign in to comment.