55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
from atst.models import AuditEvent
|
|
|
|
from tests.factories import (
|
|
ApplicationFactory,
|
|
ApplicationRoleFactory,
|
|
EnvironmentFactory,
|
|
UserFactory,
|
|
)
|
|
|
|
|
|
def test_application_num_users():
|
|
application = ApplicationFactory.create(
|
|
environments=[{"name": "dev"}, {"name": "staging"}, {"name": "prod"}]
|
|
)
|
|
assert application.num_users == 0
|
|
|
|
ApplicationRoleFactory.create(application=application)
|
|
assert application.num_users == 1
|
|
|
|
|
|
def test_application_environments_excludes_deleted():
|
|
app = ApplicationFactory.create()
|
|
env = EnvironmentFactory.create(application=app)
|
|
EnvironmentFactory.create(application=app, deleted=True)
|
|
assert len(app.environments) == 1
|
|
assert app.environments[0].id == env.id
|
|
|
|
|
|
def test_audit_event_for_application_deletion(session):
|
|
app = ApplicationFactory.create()
|
|
app.deleted = True
|
|
session.add(app)
|
|
session.commit()
|
|
|
|
update_event = (
|
|
session.query(AuditEvent)
|
|
.filter(AuditEvent.resource_id == app.id, AuditEvent.action == "update")
|
|
.one()
|
|
)
|
|
assert update_event.changed_state.get("deleted")
|
|
assert update_event.changed_state["deleted"] == [False, True]
|
|
|
|
|
|
def test_has_app_member():
|
|
user = UserFactory.create()
|
|
app = ApplicationFactory.create()
|
|
ApplicationRoleFactory.create(user=user, application=app)
|
|
assert app.has_member(user)
|
|
|
|
|
|
def test_does_not_have_app_member():
|
|
user = UserFactory.create()
|
|
app = ApplicationFactory.create()
|
|
assert not app.has_member(user)
|