Skip to content

Commit

Permalink
Consolidate member test fixtures (#439)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlanCoding authored Jun 7, 2024
1 parent 5663b33 commit a5dec8e
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
20 changes: 0 additions & 20 deletions test_app/tests/authentication/conftest.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import pytest

from ansible_base.lib.utils.auth import get_organization_model, get_team_model
from ansible_base.rbac import permission_registry
from ansible_base.rbac.models import RoleDefinition

SYSTEM_ROLE_NAME = 'System role'
Expand All @@ -14,21 +12,3 @@ def system_role():
return RoleDefinition.objects.create(
name=SYSTEM_ROLE_NAME,
)


@pytest.fixture
def team_member_role():
return RoleDefinition.objects.create(
name=TEAM_MEMBER_ROLE_NAME,
content_type=permission_registry.content_type_model.objects.get_for_model(get_team_model()),
managed=True,
)


@pytest.fixture
def organization_member_role():
return RoleDefinition.objects.create(
name=ORG_MEMBER_ROLE_NAME,
content_type=permission_registry.content_type_model.objects.get_for_model(get_organization_model()),
managed=True,
)
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_validate_role_system_role(self, serializer, system_role):
serializer.validate(dict(name="authentication_map_5", map_type="organization", role=SYSTEM_ROLE_NAME, organization='test_org'))
assert str(e.value) == "{'role': ErrorDetail(string='For an organization map type you must specify an organization based role', code='invalid')}"

def test_validate_role_team_role(self, serializer, team_member_role):
def test_validate_role_team_role(self, serializer, member_rd):
with pytest.raises(ValidationError) as e:
serializer.validate(dict(name="authentication_map_1", map_type="role", role=TEAM_MEMBER_ROLE_NAME))
assert set(e.value.detail.keys()) == {'organization', 'team'}
Expand All @@ -106,7 +106,7 @@ def test_validate_role_team_role(self, serializer, team_member_role):
)
assert str(e.value) == "{'role': ErrorDetail(string='For an organization map type you must specify an organization based role', code='invalid')}"

def test_validate_role_organization_role(self, serializer, organization_member_role):
def test_validate_role_organization_role(self, serializer, org_member_rd):
with pytest.raises(ValidationError) as e:
serializer.validate(dict(name="authentication_map_1", map_type="role", role=ORG_MEMBER_ROLE_NAME))
assert str(e.value) == "{'organization': ErrorDetail(string='You must specify an organization with the selected role', code='invalid')}"
Expand Down

0 comments on commit a5dec8e

Please sign in to comment.