Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make resource urls optional #2844

Merged
merged 6 commits into from Jun 3, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion ckan/lib/dictization/model_dictize.py
Expand Up @@ -113,7 +113,7 @@ def resource_dictize(res, context):
resource_id=res.id,
filename=cleaned_name,
qualified=True)
elif not urlparse.urlsplit(url).scheme and not context.get('for_edit'):
elif resource['url'] and not urlparse.urlsplit(url).scheme and not context.get('for_edit'):
resource['url'] = u'http://' + url.lstrip('/')
return resource

Expand Down
3 changes: 2 additions & 1 deletion ckan/logic/action/create.py
Expand Up @@ -280,7 +280,8 @@ def resource_create(context, data_dict):
user = context['user']

package_id = _get_or_bust(data_dict, 'package_id')
_get_or_bust(data_dict, 'url')
if not data_dict.get('url'):
data_dict['url'] = ''

pkg_dict = _get_action('package_show')(
dict(context, return_type='dict'),
Expand Down
2 changes: 2 additions & 0 deletions ckan/logic/action/update.py
Expand Up @@ -58,6 +58,8 @@ def resource_update(context, data_dict):
model = context['model']
user = context['user']
id = _get_or_bust(data_dict, "id")
if not data_dict.get('url'):
data_dict['url'] = ''

resource = model.Resource.get(id)
context["resource"] = resource
Expand Down
2 changes: 1 addition & 1 deletion ckan/logic/schema.py
Expand Up @@ -79,7 +79,7 @@ def default_resource_schema():
'id': [ignore_empty, unicode],
'revision_id': [ignore_missing, unicode],
'package_id': [ignore],
'url': [not_empty, unicode, remove_whitespace],
'url': [ignore_missing, unicode, remove_whitespace],
'description': [ignore_missing, unicode],
'format': [if_empty_guess_format, ignore_missing, clean_format, unicode],
'hash': [ignore_missing, unicode],
Expand Down
11 changes: 0 additions & 11 deletions ckan/tests/legacy/lib/test_dictization_schema.py
Expand Up @@ -113,19 +113,9 @@ def test_1_package_schema(self):

assert errors == {
'name': [u'That URL is already in use.'],
'resources': [{}, {'url': [u'Missing value']}]
}, pformat(errors)

data["id"] = package_id

converted_data, errors = validate(data,
default_update_package_schema(),
self.context)

assert errors == {
'resources': [{}, {'url': [u'Missing value']}]
}, pformat(errors)

data['name'] = '????jfaiofjioafjij'

converted_data, errors = validate(data,
Expand All @@ -134,7 +124,6 @@ def test_1_package_schema(self):
assert errors == {
'name': [u'Must be purely lowercase alphanumeric (ascii) '
'characters and these symbols: -_'],
'resources': [{}, {'url': [u'Missing value']}]
}, pformat(errors)

def test_2_group_schema(self):
Expand Down
11 changes: 8 additions & 3 deletions ckan/tests/logic/action/test_create.py
Expand Up @@ -403,15 +403,20 @@ def test_it_requires_package_id(self):
assert_raises(logic.ValidationError, helpers.call_action,
'resource_create', **data_dict)

def test_it_requires_url(self):
def test_doesnt_require_url(self):
user = factories.User()
dataset = factories.Dataset(user=user)
data_dict = {
'package_id': dataset['id']
}
new_resouce = helpers.call_action('resource_create', **data_dict)

assert_raises(logic.ValidationError, helpers.call_action,
'resource_create', **data_dict)
data_dict = {
'id': new_resouce['id']
}
stored_resource = helpers.call_action('resource_show', **data_dict)

assert not stored_resource['url']


class TestMemberCreate(object):
Expand Down