Skip to content

Commit

Permalink
[#652] Make the private dataset test work
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Apr 18, 2013
1 parent aa6e38c commit 3f4363e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
7 changes: 3 additions & 4 deletions ckanext/datastore/tests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,18 +258,17 @@ def test_create_basic(self):
'fields': [{'id': 'boo%k', 'type': 'text'},
{'id': 'author', 'type': 'json'}],
'indexes': [['boo%k', 'author'], 'author'],
'records': [
{'boo%k': 'crime', 'author': ['tolstoy', 'dostoevsky']},
'records': [{'boo%k': 'crime', 'author': ['tolstoy', 'dostoevsky']},
{'boo%k': 'annakarenina', 'author': ['tolstoy', 'putin']},
{'boo%k': 'warandpeace'}] # treat author as null
}
### Firstly test to see if resource things it has datastore table
### Firstly test to see whether resource has no datastore table yet
postparams = '%s=1' % json.dumps({'id': resource.id})
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/resource_show', params=postparams,
extra_environ=auth)
res_dict = json.loads(res.body)
assert res_dict['result']['datastore_active'] == False
assert res_dict['result']['datastore_active'] is False

postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.sysadmin_user.apikey)}
Expand Down
34 changes: 23 additions & 11 deletions ckanext/datastore/tests/test_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,22 +102,34 @@ def test_search_private_dataset(self):
context = {
'user': self.sysadmin_user.name,
'model': model}
p.toolkit.get_action('bulk_update_private')(
package = p.toolkit.get_action('package_create')(
context,
{'datasets': [self.dataset.id],
'org_id': group.id})
p.toolkit.get_action('member_delete')(
{'name': 'privatedataset',
'private': True,
'title': "A private dataset that the normal user can't see",
'groups': [{
'id': group.id
}]})
resource = p.toolkit.get_action('resource_create')(
context,
{'object': self.normal_user.id,
'id': group.id,
'object_type': 'user'})
#self.dataset = model.Package.get('annakarenina')
#print self.dataset
data = {'resource_id': self.data['resource_id']}
{'name': 'privateresource',
'url': 'https://www.example.com/',
'package_id': package['id']})

postparams = '%s=1' % json.dumps({
'resource_id': resource['id'],
})
auth = {'Authorization': str(self.sysadmin_user.apikey)}
res = self.app.post('/api/action/datastore_create', params=postparams,
extra_environ=auth)
res_dict = json.loads(res.body)
assert res_dict['success'] is True

data = {'resource_id': resource['id']}
postparams = '%s=1' % json.dumps(data)
auth = {'Authorization': str(self.normal_user.apikey)}
res = self.app.post('/api/action/datastore_search', params=postparams,
extra_environ=auth)
extra_environ=auth, status=403)
res_dict = json.loads(res.body)
assert res_dict['success'] is False

Expand Down

0 comments on commit 3f4363e

Please sign in to comment.