-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #866 -- Makeing sure organizaiton roles are always unique
- Add unique constraint to OrganizationRole model - Add integrity checks for unique constraints to serializers - Additional API tests
- Loading branch information
1 parent
30dccde
commit a5dd67b
Showing
7 changed files
with
72 additions
and
30 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
cadasta/organization/migrations/0003_add_organizationrole_unique.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.9.6 on 2016-10-26 08:49 | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('organization', '0002_unique_org_project_names'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterUniqueTogether( | ||
name='organizationrole', | ||
unique_together=set([('organization', 'user')]), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -373,7 +373,6 @@ def test_set_roles_with_username(self): | |
|
||
role = OrganizationRole.objects.get(user=user, organization=org) | ||
assert role.admin is True | ||
assert len(mail.outbox) == 1 | ||
|
||
def test_set_roles_with_email(self): | ||
user = UserFactory.create() | ||
|
@@ -392,7 +391,6 @@ def test_set_roles_with_email(self): | |
|
||
role = OrganizationRole.objects.get(user=user, organization=org) | ||
assert role.admin is True | ||
assert len(mail.outbox) == 1 | ||
|
||
def test_set_roles_for_user_that_does_not_exist(self): | ||
org = OrganizationFactory.create() | ||
|
@@ -418,11 +416,22 @@ def test_set_roles_for_duplicate_username(self): | |
|
||
with pytest.raises(ValidationError): | ||
serializer.is_valid(raise_exception=True) | ||
print(serializer.errors) | ||
assert (_('More than one user found for username or email ' | ||
'{email}').format(email='[email protected]') | ||
in serializer.errors['username']) | ||
|
||
def test_set_role_when_role_exists(self): | ||
user = UserFactory.create() | ||
org = OrganizationFactory.create(add_users=[user]) | ||
serializer = serializers.OrganizationUserSerializer( | ||
data={'username': user.email, 'admin': 'True'}, | ||
partial=True, | ||
context={'organization': org} | ||
) | ||
assert serializer.is_valid() is False | ||
assert ("Not able to add member. The role already exists." in | ||
serializer.errors['username']) | ||
|
||
def test_update_roles_for_user(self): | ||
user = UserFactory.create() | ||
org = OrganizationFactory.create(add_users=[user]) | ||
|
@@ -516,6 +525,20 @@ def test_set_roles_for_user_that_does_not_exist(self): | |
'does not exist').format(username='some-user') | ||
in serializer.errors['username']) | ||
|
||
def test_set_role_when_role_exists(self): | ||
user = UserFactory.create() | ||
org = OrganizationFactory.create(add_users=[user]) | ||
project = ProjectFactory.create(organization=org) | ||
ProjectRole.objects.create(user=user, project=project) | ||
serializer = serializers.ProjectUserSerializer( | ||
data={'username': user.username, 'role': 'DC'}, | ||
partial=True, | ||
context={'project': project} | ||
) | ||
assert serializer.is_valid() is False | ||
assert ("Not able to add member. The role already exists." in | ||
serializer.errors['username']) | ||
|
||
def test_update_roles_for_user(self): | ||
user = UserFactory.create() | ||
project = ProjectFactory.create(add_users=[user]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters