Skip to content

Commit

Permalink
Add tests for related actions
Browse files Browse the repository at this point in the history
  • Loading branch information
nigelbabu committed Oct 21, 2013
1 parent 4f6e390 commit 839a098
Showing 1 changed file with 61 additions and 0 deletions.
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 839a098

Please sign in to comment.