def test_disable_checks_env_role_provisioning_status(): environment = EnvironmentFactory.create( cloud_id="cloud-id", root_user_info={"credentials": "credentials"}) env_role1 = EnvironmentRoleFactory.create(environment=environment) assert not env_role1.csp_user_id env_role1 = EnvironmentRoles.disable(env_role1.id) assert env_role1.disabled env_role2 = EnvironmentRoleFactory.create(environment=environment, csp_user_id="123456") assert env_role2.csp_user_id env_role2 = EnvironmentRoles.disable(env_role2.id) assert env_role2.disabled
def test_disable_checks_env_provisioning_status(session): environment = EnvironmentFactory.create() assert environment.is_pending env_role1 = EnvironmentRoleFactory.create(environment=environment) env_role1 = EnvironmentRoles.disable(env_role1.id) assert env_role1.disabled environment.cloud_id = "cloud-id" environment.root_user_info = {"credentials": "credentials"} session.add(environment) session.commit() session.refresh(environment) assert not environment.is_pending env_role2 = EnvironmentRoleFactory.create(environment=environment) env_role2 = EnvironmentRoles.disable(env_role2.id) assert env_role2.disabled
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_environment_roles_do_not_include_deleted(): member_list = [ { "role_name": CSPRole.BASIC_ACCESS.value }, { "role_name": CSPRole.BASIC_ACCESS.value }, { "role_name": CSPRole.BASIC_ACCESS.value }, ] env = EnvironmentFactory.create(members=member_list) role_1 = env.roles[0] role_2 = env.roles[1] EnvironmentRoles.delete(role_1.application_role_id, env.id) EnvironmentRoles.disable(role_2.id) assert len(env.roles) == 2
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()