Skip to content

Commit

Permalink
[#627] Allow to create private datasets
Browse files Browse the repository at this point in the history
The private field was not present on the default package schema, used by
default_create_package_schema, so if you defined private in your package
dict it was ignored. This commit adds it to the default package schema
(ignoring it if not present).
  • Loading branch information
amercader committed Mar 13, 2013
1 parent 7afd580 commit ab9396e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions ckan/logic/schema.py
Expand Up @@ -130,6 +130,7 @@ def default_package_schema():
'state': [ignore_not_package_admin, ignore_missing],
'type': [ignore_missing, unicode],
'owner_org': [owner_org_validator, unicode],
'private': [ignore_missing, boolean_validator],
'__extras': [ignore],
'__junk': [empty],
'resources': default_resource_schema(),
Expand Down
54 changes: 54 additions & 0 deletions ckan/tests/logic/test_action.py
Expand Up @@ -179,6 +179,60 @@ def test_03_create_update_package(self):
package_created.pop('metadata_modified')
assert package_updated == package_created#, (pformat(json.loads(res.body)), pformat(package_created['result']))

def test_03_create_private_package(self):

def _do_request(package_dict):
postparams = '%s=1' % json.dumps(package_dict)
res = self.app.post('/api/action/package_create', params=postparams,
extra_environ={'Authorization': str(self.sysadmin_user.apikey)})
package_created = json.loads(res.body)['result']
return package_created

# Create a dataset without specifying visibility
package_dict = {
'extras': [{'key': u'original media','value': u'"book"'}],
'license_id': u'other-open',
'maintainer_email': None,
'name': u'annakarenina_vis',
'notes': u'Some test now',
'resources': [{'alt_url': u'alt123',
'description': u'Full text.',
'extras': {u'alt_url': u'alt123', u'size': u'123'},
'format': u'plain text',
'hash': u'abc123',
'position': 0,
'url': u'http://www.annakarenina.com/download/'},
{'alt_url': u'alt345',
'description': u'Index of the novel',
'extras': {u'alt_url': u'alt345', u'size': u'345'},
'format': u'JSON',
'hash': u'def456',
'position': 1,
'url': u'http://www.annakarenina.com/index.json'}],
'tags': [{'name': u'russian'}, {'name': u'tolstoy'}],
'title': u'A Novel By Tolstoy',
'url': u'http://www.annakarenina.com',
'version': u'0.7a',
}

package_created = _do_request(package_dict)
assert package_created['private'] is False

# Create a new one, explicitly saying it is public
package_dict['name'] = u'annakareninanew_vis_public'
package_dict['private'] = False

package_created_public = _do_request(package_dict)
assert package_created_public['private'] is False

# Create a new one, explicitly saying it is private
package_dict['name'] = u'annakareninanew_vis_private'
package_dict['private'] = True

package_created_private = _do_request(package_dict)
assert package_created_private['private'] is True


def test_18_create_package_not_authorized(self):
# I cannot understand the logic on this one we seem to be user
# tester but no idea how.
Expand Down

0 comments on commit ab9396e

Please sign in to comment.