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
def update_env_role(cls, environment, application_role, new_role): env_role = EnvironmentRoles.get_for_update(application_role.id, environment.id) if env_role and new_role and (env_role.disabled or env_role.deleted): raise DisabledError("environment_role", env_role.id) if env_role and env_role.role != new_role and not env_role.disabled: env_role.role = new_role db.session.add(env_role) elif not env_role and new_role: env_role = EnvironmentRoles.create( application_role=application_role, environment=environment, role=new_role, ) db.session.add(env_role) if env_role and not new_role and not env_role.disabled: EnvironmentRoles.disable(env_role.id) db.session.commit()