Skip to content

Commit

Permalink
Merge branch '504-related-update-schema' of github.com:okfn/ckan into…
Browse files Browse the repository at this point in the history
… 504-related-update-schema
  • Loading branch information
johnglover committed Oct 24, 2013
2 parents 3d36ae1 + 839a098 commit 4f23e0d
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ckan/logic/action/update.py
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions ckan/logic/schema.py
Expand Up @@ -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 = {
Expand Down
61 changes: 61 additions & 0 deletions ckan/tests/logic/test_action.py
Expand Up @@ -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']


0 comments on commit 4f23e0d

Please sign in to comment.