In the future, an `application_invitation1 will not refer to a `user` until someone accepts the invitation; they'll only reference an `application_role`. When a user is invited to an application, the inviter can specify the environments the invitee should have access to. For this to be possible, an `environment_role` should reference an `application_role`, because no `user` entity will be known at that time. In addition to updating all the models and domain methods necessary for this change, this commit deletes unused code and tests that were dependent on `environment_roles` having a `user_id` foreign key.
53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from atst.domain.permission_sets import PermissionSets
|
|
from atst.models.audit_event import AuditEvent
|
|
|
|
from tests.factories import *
|
|
|
|
|
|
def test_has_application_role_history(session):
|
|
owner = UserFactory.create()
|
|
user = UserFactory.create()
|
|
|
|
PortfolioFactory.create(
|
|
owner=owner,
|
|
applications=[
|
|
{
|
|
"name": "starkiller",
|
|
"environments": [
|
|
{
|
|
"name": "bridge",
|
|
"members": [{"user": user, "role_name": "developer"}],
|
|
}
|
|
],
|
|
}
|
|
],
|
|
)
|
|
|
|
app_role = user.application_roles[0]
|
|
app_role.permission_sets = [
|
|
PermissionSets.get(PermissionSets.EDIT_APPLICATION_TEAM)
|
|
]
|
|
session.add(app_role)
|
|
session.commit()
|
|
|
|
changed_event = (
|
|
session.query(AuditEvent)
|
|
.filter(AuditEvent.resource_id == app_role.id, AuditEvent.action == "update")
|
|
.one()
|
|
)
|
|
old_state, new_state = changed_event.changed_state["permission_sets"]
|
|
assert old_state == [PermissionSets.VIEW_APPLICATION]
|
|
assert new_state == [PermissionSets.EDIT_APPLICATION_TEAM]
|
|
|
|
|
|
def test_environment_roles():
|
|
application = ApplicationFactory.create()
|
|
environment = EnvironmentFactory.create(application=application)
|
|
user = UserFactory.create()
|
|
application_role = ApplicationRoleFactory.create(application=application, user=user)
|
|
environment_role = EnvironmentRoleFactory.create(
|
|
environment=environment, application_role=application_role
|
|
)
|
|
|
|
assert application_role.environment_roles == [environment_role]
|