Skip to content

Commit

Permalink
add previously removed BatchUpdateRolesMixin (#1464)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkonie committed Aug 7, 2024
1 parent ba46c14 commit 7033272
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 31 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ Changelog for the **SODAR Core** Django app package. Loosely follows the
Unreleased
==========

Added
-----

- **Projectroles**
- Previously removed ``BatchUpdateRolesMixin`` (#1464)

Fixed
-----

- **Projectroles**
- ``BatchUpdateRolesMixin`` removal breaking tests in other repos (#1464)
- **Timeline**
- Deprecated link dict ``blank`` field assumed as mandatory (#1462)

Expand Down
77 changes: 46 additions & 31 deletions projectroles/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,31 @@
LDAP_DOMAIN = 'EXAMPLE'


# Mixins -----------------------------------------------------------------------


class BatchUpdateRolesMixin:
"""
Helpers for batchupdateroles testing.
NOTE: May be needed by external repos for testing, do not remove!
"""

file = None

def write_file(self, data):
"""Write data to temporary CSV file"""
if not isinstance(data[0], list):
data = [data]
self.file.write(
bytes('\n'.join([';'.join(r) for r in data]), encoding='utf-8')
)
self.file.close()


# Tests ------------------------------------------------------------------------


class TestAddRemoteSite(
ProjectMixin,
RoleMixin,
Expand Down Expand Up @@ -231,19 +256,11 @@ class TestBatchUpdateRoles(
RoleMixin,
RoleAssignmentMixin,
ProjectInviteMixin,
BatchUpdateRolesMixin,
TestCase,
):
"""Tests for batchupdateroles command"""

def _write_file(self, data):
"""Write data to temporary CSV file"""
if not isinstance(data[0], list):
data = [data]
self.file.write(
bytes('\n'.join([';'.join(r) for r in data]), encoding='utf-8')
)
self.file.close()

def setUp(self):
super().setUp()
# Init roles
Expand Down Expand Up @@ -288,7 +305,7 @@ def test_invite(self):
email = 'new@example.com'
self.assertEqual(ProjectInvite.objects.count(), 0)

self._write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -307,7 +324,7 @@ def test_invite_existing(self):
self.make_invite(email, self.project, self.role_guest, self.user_owner)
self.assertEqual(ProjectInvite.objects.count(), 1)

self._write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -325,7 +342,7 @@ def test_invite_multi_user(self):
[self.project_uuid, email, PROJECT_ROLE_GUEST],
[self.project_uuid, email2, PROJECT_ROLE_GUEST],
]
self._write_file(fd)
self.write_file(fd)
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -342,7 +359,7 @@ def test_invite_multi_project(self):
[self.category_uuid, email, PROJECT_ROLE_GUEST],
[self.project_uuid, email, PROJECT_ROLE_GUEST],
]
self._write_file(fd)
self.write_file(fd)
# NOTE: Using user_owner_cat as they have perms for both projects
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner_cat.username}
Expand All @@ -358,7 +375,7 @@ def test_invite_multi_project(self):

def test_invite_owner(self):
"""Test inviting an owner (should fail)"""
self._write_file(
self.write_file(
[self.project_uuid, 'new@example.com', PROJECT_ROLE_OWNER]
)
self.command.handle(
Expand All @@ -369,7 +386,7 @@ def test_invite_owner(self):

def test_invite_delegate(self):
"""Test inviting a delegate"""
self._write_file(
self.write_file(
[self.project_uuid, 'new@example.com', PROJECT_ROLE_DELEGATE]
)
self.command.handle(
Expand All @@ -383,7 +400,7 @@ def test_invite_delegate_no_perms(self):
"""Test inviting a delegate without perms (should fail)"""
user_delegate = self.make_user('delegate')
self.make_assignment(self.project, user_delegate, self.role_delegate)
self._write_file(
self.write_file(
[self.project_uuid, 'new@example.com', PROJECT_ROLE_DELEGATE]
)
self.command.handle(
Expand All @@ -396,7 +413,7 @@ def test_invite_delegate_limit(self):
"""Test inviting a delegate with limit reached (should fail)"""
user_delegate = self.make_user('delegate')
self.make_assignment(self.project, user_delegate, self.role_delegate)
self._write_file(
self.write_file(
[self.project_uuid, 'new@example.com', PROJECT_ROLE_DELEGATE]
)
self.command.handle(
Expand All @@ -413,7 +430,7 @@ def test_role_add(self):
user_new.save()
self.assertEqual(ProjectInvite.objects.count(), 0)

self._write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -439,7 +456,7 @@ def test_role_update(self):
1,
)

self._write_file([self.project_uuid, email, PROJECT_ROLE_CONTRIBUTOR])
self.write_file([self.project_uuid, email, PROJECT_ROLE_CONTRIBUTOR])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -455,7 +472,7 @@ def test_role_update_owner(self):
self.user_owner.email = email
self.user_owner.save()

self._write_file([self.project_uuid, email, PROJECT_ROLE_CONTRIBUTOR])
self.write_file([self.project_uuid, email, PROJECT_ROLE_CONTRIBUTOR])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -482,7 +499,7 @@ def test_role_update_delegate_no_perms(self):
user_delegate = self.make_user('delegate')
self.make_assignment(self.project, user_delegate, self.role_delegate)

self._write_file([self.project_uuid, email, PROJECT_ROLE_DELEGATE])
self.write_file([self.project_uuid, email, PROJECT_ROLE_DELEGATE])
self.command.handle(
**{'file': self.file.name, 'issuer': user_delegate.username}
)
Expand All @@ -502,7 +519,7 @@ def test_role_update_delegate_limit(self):
user_delegate = self.make_user('delegate')
self.make_assignment(self.project, user_delegate, self.role_delegate)

self._write_file([self.project_uuid, email, PROJECT_ROLE_DELEGATE])
self.write_file([self.project_uuid, email, PROJECT_ROLE_DELEGATE])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -514,7 +531,7 @@ def test_role_update_delegate_limit(self):

def test_role_add_inherited_owner(self):
"""Test adding role with inherited owner rank (should fail)"""
self._write_file(
self.write_file(
[
self.project_uuid,
self.user_owner_cat.email,
Expand All @@ -540,7 +557,7 @@ def test_role_add_inherited_higher(self):
user_new.email = 'user_new@example.com'
self.make_assignment(self.category, user_new, self.role_guest)

self._write_file(
self.write_file(
[
self.project_uuid,
user_new.email,
Expand All @@ -566,7 +583,7 @@ def test_role_add_inherited_equal(self):
user_new.email = 'user_new@example.com'
self.make_assignment(self.category, user_new, self.role_contributor)

self._write_file(
self.write_file(
[
self.project_uuid,
user_new.email,
Expand All @@ -592,9 +609,7 @@ def test_role_add_inherited_lower(self):
user_new.email = 'user_new@example.com'
self.make_assignment(self.category, user_new, self.role_contributor)

self._write_file(
[self.project_uuid, user_new.email, PROJECT_ROLE_GUEST]
)
self.write_file([self.project_uuid, user_new.email, PROJECT_ROLE_GUEST])
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -621,7 +636,7 @@ def test_invite_and_update(self):
[self.project_uuid, email, PROJECT_ROLE_GUEST],
[self.project_uuid, email2, PROJECT_ROLE_GUEST],
]
self._write_file(fd)
self.write_file(fd)
self.command.handle(
**{'file': self.file.name, 'issuer': self.user_owner.username}
)
Expand All @@ -641,7 +656,7 @@ def test_command_no_issuer(self):
admin.is_superuser = True
admin.save()
email = 'new@example.com'
self._write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.command.handle(**{'file': self.file.name, 'issuer': None})
invite = ProjectInvite.objects.first()
self.assertEqual(invite.issuer, admin)
Expand All @@ -650,7 +665,7 @@ def test_command_no_perms(self):
"""Test invite with issuer who lacks permissions for a project"""
issuer = self.make_user('issuer')
email = 'new@example.com'
self._write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.write_file([self.project_uuid, email, PROJECT_ROLE_GUEST])
self.command.handle(
**{'file': self.file.name, 'issuer': issuer.username}
)
Expand Down

0 comments on commit 7033272

Please sign in to comment.