示例#1
0
文件: __init__.py 项目: v1psta/atst
    def get_user(self):
        try:
            return Users.get_by_dod_id(self.parsed_sdn["dod_id"])

        except NotFoundError:
            email = self._get_user_email()
            return Users.create(permission_sets=[],
                                email=email,
                                **self.parsed_sdn)
示例#2
0
def get_users():
    users = []
    for dev_user in DEV_USERS.values():
        try:
            user = Users.create(**dev_user)
        except AlreadyExistsError:
            user = Users.get_by_dod_id(dev_user["dod_id"])

        users.append(user)
    return users
示例#3
0
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)
示例#4
0
def dev_new_user():
    first_name = request.args.get("first_name", None)
    last_name = request.args.get("last_name", None)
    dod_id = request.args.get("dod_id", None)

    if None in [first_name, last_name, dod_id]:
        raise IncompleteInfoError()

    try:
        Users.get_by_dod_id(dod_id)
        raise AlreadyExistsError("User with dod_id {}".format(dod_id))
    except NotFoundError:
        pass

    new_user = {"first_name": first_name, "last_name": last_name}

    created_user = Users.create(dod_id, **new_user)

    current_user_setup(created_user)
    return redirect(redirect_after_login_url())
示例#5
0
文件: test_users.py 项目: robgil/atst
def test_create_user_with_nonexistent_permission_set():
    with pytest.raises(NotFoundError):
        Users.create(DOD_ID, permission_sets=["nonexistent"])
示例#6
0
文件: test_users.py 项目: robgil/atst
def test_create_user_with_existing_email():
    Users.create(DOD_ID, email="*****@*****.**")
    with pytest.raises(AlreadyExistsError):
        Users.create(DOD_ID, email="*****@*****.**")
示例#7
0
文件: test_users.py 项目: robgil/atst
def test_create_user():
    user = Users.create(DOD_ID)
    assert user.dod_id == DOD_ID
示例#8
0
文件: test_users.py 项目: v1psta/atst
def test_create_user():
    user = Users.create(DOD_ID, **REQUIRED_KWARGS)
    assert user.dod_id == DOD_ID