def test_create_application_role(): application = ApplicationFactory.create() user = UserFactory.create() application_role = ApplicationRoles.create( application=application, user=user, permission_set_names=[PermissionSets.EDIT_APPLICATION_TEAM], ) assert application_role.permission_sets == PermissionSets.get_many([ PermissionSets.EDIT_APPLICATION_TEAM, PermissionSets.VIEW_APPLICATION ]) assert application_role.application == application assert application_role.user == user
def add_applications_to_portfolio(portfolio): applications = random_applications() for application_data in applications: application = Applications.create( portfolio.owner, portfolio=portfolio, name=application_data["name"], description=application_data["description"], environment_names=application_data["environments"], ) users = random.sample(APPLICATION_USERS, k=random.randint(1, 5)) for user_data in users: try: user = Users.get_by_dod_id(user_data["dod_id"]) except NotFoundError: user = Users.create( user_data["dod_id"], None, first_name=user_data["first_name"], last_name=user_data["last_name"], email=user_data["email"], ) app_role = ApplicationRoles.create( user=user, application=application, permission_set_names=[PermissionSets.EDIT_APPLICATION_TEAM], ) ApplicationInvitations.create(portfolio.owner, app_role, user_data, commit=True) user_environments = random.sample( application.environments, k=random.randint(1, len(application.environments)), ) for env in user_environments: role = random.choice([e.value for e in CSPRole]) EnvironmentRoles.create(application_role=app_role, environment=env, role=role)