def access_environment(environment_id): env_role = EnvironmentRoles.get_by_user_and_environment( g.current_user.id, environment_id) login_url = app.csp.cloud.get_environment_login_url(env_role.environment) return redirect(url_for("atst.csp_environment_access", login_url=login_url))
def wrap_environment_role_lookup(user, environment_id=None, **kwargs): env_role = EnvironmentRoles.get_by_user_and_environment( user.id, environment_id) if not env_role: raise UnauthorizedError(user, "access environment {}".format(environment_id)) return True
def test_environment_roles(): application = ApplicationFactory.create() environment1 = EnvironmentFactory.create(application=application) environment2 = EnvironmentFactory.create(application=application) user = UserFactory.create() application_role = ApplicationRoleFactory.create(application=application, user=user) environment_role1 = EnvironmentRoleFactory.create( environment=environment1, application_role=application_role) EnvironmentRoleFactory.create(environment=environment2, application_role=application_role, deleted=True) assert not EnvironmentRoles.get_by_user_and_environment( user.id, environment2.id)
def test_get_by_user_and_environment(application_role, environment): expected_role = EnvironmentRoleFactory.create( application_role=application_role, environment=environment) actual_role = EnvironmentRoles.get_by_user_and_environment( application_role.user.id, environment.id) assert expected_role == actual_role