-
Notifications
You must be signed in to change notification settings - Fork 412
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Convert organisations permissions TestCase to normal test func…
…tion (#3323)
- Loading branch information
Showing
1 changed file
with
38 additions
and
42 deletions.
There are no files selected for viewing
80 changes: 38 additions & 42 deletions
80
api/tests/unit/organisations/permissions/test_unit_organisations_permissions.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 |
---|---|---|
@@ -1,47 +1,43 @@ | ||
from unittest import TestCase, mock | ||
from unittest import mock | ||
|
||
import pytest | ||
|
||
from organisations.models import Organisation, OrganisationRole | ||
from organisations.models import Organisation | ||
from organisations.permissions.permissions import OrganisationUsersPermission | ||
from users.models import FFAdminUser | ||
|
||
mock_request = mock.MagicMock | ||
mock_view = mock.MagicMock | ||
|
||
|
||
@pytest.mark.django_db | ||
class OrganisationUsersPermissionTestCase(TestCase): | ||
def setUp(self) -> None: | ||
self.organisation = Organisation.objects.create(name="Test") | ||
self.user = FFAdminUser.objects.create(email="[email protected]") | ||
self.org_admin = FFAdminUser.objects.create(email="[email protected]") | ||
|
||
self.user.add_organisation(self.organisation) | ||
self.org_admin.add_organisation(self.organisation, OrganisationRole.ADMIN) | ||
|
||
self.permissions = OrganisationUsersPermission() | ||
|
||
mock_view.kwargs = {"organisation_pk": self.organisation.id} | ||
|
||
def test_org_user_can_list_users(self): | ||
# Given | ||
mock_request.user = self.user | ||
mock_view.action = "list" | ||
|
||
# When | ||
result = self.permissions.has_permission(mock_request, mock_view) | ||
|
||
# Then | ||
assert result | ||
|
||
def test_org_user_cannot_create_user(self): | ||
# Given | ||
mock_request.user = self.user | ||
mock_view.action = "create" | ||
|
||
# When | ||
result = self.permissions.has_permission(mock_request, mock_view) | ||
|
||
# Then | ||
assert not result | ||
def test_org_user_can_list_users( | ||
staff_user: FFAdminUser, | ||
organisation: Organisation, | ||
) -> None: | ||
# Given | ||
mock_request = mock.MagicMock(user=staff_user) | ||
mock_view = mock.MagicMock( | ||
action="list", | ||
kwargs={"organisation_pk": organisation.id}, | ||
) | ||
permissions = OrganisationUsersPermission() | ||
|
||
# When | ||
result = permissions.has_permission(mock_request, mock_view) | ||
|
||
# Then | ||
assert result is True | ||
|
||
|
||
def test_org_user_cannot_create_user( | ||
staff_user: FFAdminUser, | ||
organisation: Organisation, | ||
) -> None: | ||
# Given | ||
mock_request = mock.MagicMock(user=staff_user) | ||
mock_view = mock.MagicMock( | ||
action="create", | ||
kwargs={"organisation_pk": organisation.id}, | ||
) | ||
permissions = OrganisationUsersPermission() | ||
|
||
# When | ||
result = permissions.has_permission(mock_request, mock_view) | ||
|
||
# Then | ||
assert result is False |