disabled env role We were only checking to see if a role was disabled or deleted before raising an error, so I added in a check to see if the user was trying to update the env role before raising an error. The error should only be raised if the role is disabled or deleted AND the user is trying to assign a new role to the env role. I also added in a disabled property to the EnvironmentRole model to make things more readable.
103 lines
3.3 KiB
Python
103 lines
3.3 KiB
Python
import pytest
|
|
|
|
from atst.domain.environment_roles import EnvironmentRoles
|
|
from atst.models.environment_role import EnvironmentRole
|
|
|
|
from tests.factories import *
|
|
|
|
|
|
@pytest.fixture
|
|
def application_role():
|
|
user = UserFactory.create()
|
|
application = ApplicationFactory.create()
|
|
return ApplicationRoleFactory.create(application=application, user=user)
|
|
|
|
|
|
@pytest.fixture
|
|
def environment(application_role):
|
|
return EnvironmentFactory.create(application=application_role.application)
|
|
|
|
|
|
def test_create(application_role, environment, monkeypatch):
|
|
|
|
environment_role = EnvironmentRoles.create(
|
|
application_role, environment, "network admin"
|
|
)
|
|
assert environment_role.application_role == application_role
|
|
assert environment_role.environment == environment
|
|
assert environment_role.role == "network admin"
|
|
|
|
|
|
def test_get(application_role, environment):
|
|
EnvironmentRoleFactory.create(
|
|
application_role=application_role, environment=environment
|
|
)
|
|
|
|
environment_role = EnvironmentRoles.get(application_role.id, environment.id)
|
|
assert environment_role
|
|
assert environment_role.application_role == application_role
|
|
assert environment_role.environment == environment
|
|
|
|
|
|
def test_get_by_user_and_environment(application_role, environment):
|
|
expected_role = EnvironmentRoleFactory.create(
|
|
application_role=application_role, environment=environment
|
|
)
|
|
actual_role = EnvironmentRoles.get_by_user_and_environment(
|
|
application_role.user.id, environment.id
|
|
)
|
|
assert expected_role == actual_role
|
|
|
|
|
|
def test_delete(application_role, environment, monkeypatch):
|
|
env_role = EnvironmentRoleFactory.create(
|
|
application_role=application_role, environment=environment
|
|
)
|
|
assert EnvironmentRoles.delete(application_role.id, environment.id)
|
|
assert not EnvironmentRoles.delete(application_role.id, environment.id)
|
|
|
|
|
|
def test_get_for_application_member(application_role, environment):
|
|
EnvironmentRoleFactory.create(
|
|
application_role=application_role, environment=environment
|
|
)
|
|
|
|
roles = EnvironmentRoles.get_for_application_member(application_role.id)
|
|
assert len(roles) == 1
|
|
assert roles[0].environment == environment
|
|
assert roles[0].application_role == application_role
|
|
|
|
|
|
def test_get_for_application_member_does_not_return_deleted(
|
|
application_role, environment
|
|
):
|
|
EnvironmentRoleFactory.create(
|
|
application_role=application_role, environment=environment, deleted=True
|
|
)
|
|
|
|
roles = EnvironmentRoles.get_for_application_member(application_role.id)
|
|
assert len(roles) == 0
|
|
|
|
|
|
def test_disable_completed(application_role, environment):
|
|
environment_role = EnvironmentRoleFactory.create(
|
|
application_role=application_role,
|
|
environment=environment,
|
|
status=EnvironmentRole.Status.COMPLETED,
|
|
)
|
|
|
|
environment_role = EnvironmentRoles.disable(environment_role.id)
|
|
|
|
assert environment_role.disabled
|
|
|
|
|
|
def test_get_for_update(application_role, environment):
|
|
EnvironmentRoleFactory.create(
|
|
application_role=application_role, environment=environment, deleted=True
|
|
)
|
|
role = EnvironmentRoles.get_for_update(application_role.id, environment.id)
|
|
assert role
|
|
assert role.application_role == application_role
|
|
assert role.environment == environment
|
|
assert role.deleted
|