diff --git a/ckan/logic/action/get.py b/ckan/logic/action/get.py index b2d2419cd92..04e26b5e7a2 100644 --- a/ckan/logic/action/get.py +++ b/ckan/logic/action/get.py @@ -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) diff --git a/ckan/new_tests/logic/action/test_get.py b/ckan/new_tests/logic/action/test_get.py index 37ca58d52b9..ce0a1b65da6 100644 --- a/ckan/new_tests/logic/action/test_get.py +++ b/ckan/new_tests/logic/action/test_get.py @@ -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() diff --git a/ckan/tests/logic/test_action.py b/ckan/tests/logic/test_action.py index 43f3fddc2b6..b41317ab75e 100644 --- a/ckan/tests/logic/test_action.py +++ b/ckan/tests/logic/test_action.py @@ -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})