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

*_member_create don't raise validation errors #3108

Merged
merged 4 commits into from Jun 15, 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
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
8 changes: 5 additions & 3 deletions ckan/logic/schema.py
Expand Up @@ -55,8 +55,10 @@
resource_id_exists,
tag_not_in_vocabulary,
group_id_exists,
group_id_or_name_exists,
owner_org_validator,
user_name_exists,
user_id_or_name_exists,
role_exists,
datasets_with_no_organization_cannot_be_private,
list_of_strings,
Expand Down Expand Up @@ -532,9 +534,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, group_id_or_name_exists, unicode],
'username': [not_missing, user_id_or_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 @@ -152,7 +152,6 @@ def setup_class(cls):
@classmethod
def teardown_class(cls):
p.unload('image_view')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this related?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what happened here, I pushed a commit fixing it


helpers.reset_db()

def setup(self):
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