diff --git a/ckan/logic/action/update.py b/ckan/logic/action/update.py index 3db2d0d19cf..13fc147b50b 100644 --- a/ckan/logic/action/update.py +++ b/ckan/logic/action/update.py @@ -132,7 +132,7 @@ def related_update(context, data_dict): id = _get_or_bust(data_dict, "id") session = context['session'] - schema = context.get('schema') or schema_.default_related_schema() + schema = context.get('schema') or schema_.default_update_related_schema() related = model.Related.get(id) context["related"] = related diff --git a/ckan/logic/schema.py b/ckan/logic/schema.py index 41e3c724656..9fb859fde65 100644 --- a/ckan/logic/schema.py +++ b/ckan/logic/schema.py @@ -331,6 +331,15 @@ def default_related_schema(): return schema +def default_update_related_schema(): + schema = default_related_schema() + schema['id'] = [not_empty, unicode] + schema['title'] = [ignore_missing, unicode] + schema['type'] = [ignore_missing, unicode] + schema['owner_id'] = [ignore_missing, unicode] + return schema + + def default_extras_schema(): schema = { diff --git a/ckan/tests/logic/test_action.py b/ckan/tests/logic/test_action.py index ed1907ebdb8..fac25a7ba86 100644 --- a/ckan/tests/logic/test_action.py +++ b/ckan/tests/logic/test_action.py @@ -1978,3 +1978,64 @@ def _assert_we_can_add_user_to_group(self, user_id, group_id): group_ids = [g.id for g in groups] assert res['success'] is True, res assert group.id in group_ids, (group, user_groups) + + +class TestRelatedAction(WsgiAppCase): + + sysadmin_user = None + + normal_user = None + + @classmethod + def setup_class(cls): + search.clear() + CreateTestData.create() + cls.sysadmin_user = model.User.get('testsysadmin') + + @classmethod + def teardown_class(cls): + model.repo.rebuild_db() + + def _add_basic_package(self, package_name=u'test_package', **kwargs): + package = { + 'name': package_name, + 'title': u'A Novel By Tolstoy', + 'resources': [{ + 'description': u'Full text.', + 'format': u'plain text', + 'url': u'http://www.annakarenina.com/download/' + }] + } + package.update(kwargs) + + postparams = '%s=1' % json.dumps(package) + res = self.app.post('/api/action/package_create', params=postparams, + extra_environ={'Authorization': 'tester'}) + return json.loads(res.body)['result'] + + def test_01_update_add_related_item(self): + package = self._add_basic_package() + related_item = { + "description": "Testing a Description", + "url": "http://example.com/image.png", + "title": "Testing", + "featured": 0, + "image_url": "http://example.com/image.png", + "type": "idea", + "dataset_id": package['id'], + } + related_item_json = json.dumps(related_item) + res_create = self.app.post('/api/action/related_create', params=related_item_json, + extra_environ={'Authorization': 'tester'}) + assert res_create.json['success'] == True + + related_update = res_create.json['result'] + related_update = {'id': related_update['id'], 'title': 'Updated'} + related_update_json = json.dumps(related_update) + res_update = self.app.post('/api/action/related_update', params=related_update_json, + extra_environ={'Authorization': 'tester'}) + assert res_update.json['success'] == True + res_update_json = res_update.json['result'] + assert res_update_json['title'] == related_update['title'] + +