Skip to content

Commit

Permalink
[#3108] Raise validation errors on group/org_member_create
Browse files Browse the repository at this point in the history
Add not_missing to the schema and raise the errors on the action. Adds
some tests as well
  • Loading branch information
amercader committed Jun 13, 2016
1 parent 997b06c commit 99c0f33
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
3 changes: 3 additions & 0 deletions ckan/logic/action/create.py
Expand Up @@ -1372,6 +1372,9 @@ def _group_or_org_member_create(context, data_dict, is_org=False):

schema = ckan.logic.schema.member_schema()
data, errors = _validate(data_dict, schema, context)
if errors:
model.Session.rollback()
raise ValidationError(errors)

username = _get_or_bust(data_dict, 'username')
role = data_dict.get('role')
Expand Down
6 changes: 3 additions & 3 deletions ckan/logic/schema.py
Expand Up @@ -532,9 +532,9 @@ def default_follow_dataset_schema():

def member_schema():
schema = {
'id': [group_id_exists, unicode],
'username': [user_name_exists, unicode],
'role': [role_exists, unicode],
'id': [not_missing, not_empty, group_id_exists, unicode],
'username': [not_missing, user_name_exists, unicode],
'role': [not_missing, role_exists, unicode],
}
return schema

Expand Down
43 changes: 42 additions & 1 deletion ckan/tests/logic/action/test_create.py
Expand Up @@ -151,7 +151,6 @@ def setup_class(cls):

@classmethod
def teardown_class(cls):
p.unload('image_view')

helpers.reset_db()

Expand Down Expand Up @@ -485,6 +484,48 @@ def test_organization_member_creation(self):
assert_equals(new_membership['table_id'], user['id'])
assert_equals(new_membership['capacity'], 'member')

def test_group_member_creation_raises_validation_error_if_id_missing(self):

assert_raises(logic.ValidationError,
helpers.call_action, 'group_member_create',
username='someuser',
role='member',)

def test_group_member_creation_raises_validation_error_if_username_missing(self):

assert_raises(logic.ValidationError,
helpers.call_action, 'group_member_create',
id='someid',
role='member',)

def test_group_member_creation_raises_validation_error_if_role_missing(self):

assert_raises(logic.ValidationError,
helpers.call_action, 'group_member_create',
id='someid',
username='someuser',)

def test_org_member_creation_raises_validation_error_if_id_missing(self):

assert_raises(logic.ValidationError,
helpers.call_action, 'organization_member_create',
username='someuser',
role='member',)

def test_org_member_creation_raises_validation_error_if_username_missing(self):

assert_raises(logic.ValidationError,
helpers.call_action, 'organization_member_create',
id='someid',
role='member',)

def test_org_member_creation_raises_validation_error_if_role_missing(self):

assert_raises(logic.ValidationError,
helpers.call_action, 'organization_member_create',
id='someid',
username='someuser',)


class TestDatasetCreate(helpers.FunctionalTestBase):

Expand Down

0 comments on commit 99c0f33

Please sign in to comment.