atst/tests/models/test_environments.py
dandds df06d1b62f Use application_role_id on environment_roles.
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.
2019-05-31 11:21:20 -04:00

45 lines
1.3 KiB
Python

from atst.models import AuditEvent
from atst.models.environment_role import CSPRole
from atst.domain.environments import Environments
from atst.domain.applications import Applications
from tests.factories import *
def test_add_user_to_environment():
owner = UserFactory.create()
developer = UserFactory.create()
portfolio = PortfolioFactory.create(owner=owner)
application = Applications.create(
portfolio, "my test application", "It's mine.", ["dev", "staging", "prod"]
)
dev_environment = application.environments[0]
application_role = ApplicationRoleFactory.create(
user=developer, application=application
)
EnvironmentRoleFactory.create(
application_role=application_role,
environment=dev_environment,
role=CSPRole.BASIC_ACCESS.value,
)
assert developer in dev_environment.users
def test_audit_event_for_environment_deletion(session):
env = EnvironmentFactory.create(application=ApplicationFactory.create())
env.deleted = True
session.add(env)
session.commit()
update_event = (
session.query(AuditEvent)
.filter(AuditEvent.resource_id == env.id, AuditEvent.action == "update")
.one()
)
assert update_event.changed_state.get("deleted")
before, after = update_event.changed_state["deleted"]
assert not before
assert after