Exemplo n.º 1
0
    def create(cls, user, portfolio, name, description, environment_names=None):
        application = Application(
            portfolio=portfolio, name=name, description=description
        )
        db.session.add(application)

        if environment_names:
            Environments.create_many(user, application, environment_names)

        db.session.commit()
        return application
Exemplo n.º 2
0
    def update(cls, application, new_data):
        if "name" in new_data:
            application.name = new_data["name"]
        if "description" in new_data:
            application.description = new_data["description"]
        if "environment_names" in new_data:
            Environments.create_many(g.current_user, application,
                                     new_data["environment_names"])

        db.session.add(application)
        commit_or_raise_already_exists_error(message="application")
        return application
Exemplo n.º 3
0
    def update(cls, application, new_data):
        if "name" in new_data:
            application.name = new_data["name"]
        if "description" in new_data:
            application.description = new_data["description"]
        if "environment_names" in new_data:
            Environments.create_many(
                g.current_user, application, new_data["environment_names"]
            )
        db.session.add(application)
        db.session.commit()

        return application
Exemplo n.º 4
0
def test_create_environments():
    application = ApplicationFactory.create()
    environments = Environments.create_many(application.portfolio.owner,
                                            application,
                                            ["Staging", "Production"])
    for env in environments:
        assert env.cloud_id is None
Exemplo n.º 5
0
    def create(cls,
               user,
               portfolio,
               name,
               description,
               environment_names=None):
        application = Application(portfolio=portfolio,
                                  name=name,
                                  description=description)
        db.session.add(application)

        if environment_names:
            Environments.create_many(user, application, environment_names)

        commit_or_raise_already_exists_error(message="application")
        return application
Exemplo n.º 6
0
def create_demo_portfolio(name, data):
    try:
        portfolio_owner = Users.get_or_create_by_dod_id("2345678901")  # Amanda
        # auditor = Users.get_by_dod_id("3453453453")  # Sally
    except NotFoundError:
        print("Could not find demo users; will not create demo portfolio {}".
              format(name))
        return

    portfolio = Portfolios.create(
        user=portfolio_owner,
        portfolio_attrs={
            "name": name,
            "defense_component": random_service_branch()
        },
    )

    add_task_orders_to_portfolio(portfolio)
    add_members_to_portfolio(portfolio)

    for mock_application in data["applications"]:
        application = Application(portfolio=portfolio,
                                  name=mock_application.name,
                                  description="")
        env_names = [env.name for env in mock_application.environments]
        envs = Environments.create_many(portfolio.owner, application,
                                        env_names)
        db.session.add(application)
        db.session.commit()
Exemplo n.º 7
0
def create_demo_portfolio(name, data):
    try:
        portfolio_owner = Users.get_or_create_by_dod_id(
            "2345678901",
            **pick(
                [
                    "permission_sets",
                    "first_name",
                    "last_name",
                    "email",
                    "service_branch",
                    "phone_number",
                    "citizenship",
                    "designation",
                    "date_latest_training",
                ],
                DEV_USERS["amanda"],
            ),
        )  # Amanda
        # auditor = Users.get_by_dod_id("3453453453")  # Sally
    except NotFoundError:
        print("Could not find demo users; will not create demo portfolio {}".
              format(name))
        return

    portfolio = Portfolios.create(
        user=portfolio_owner,
        portfolio_attrs={
            "name": name,
            "defense_component": random_service_branch()
        },
    )

    add_task_orders_to_portfolio(portfolio)
    add_members_to_portfolio(portfolio)

    for mock_application in data["applications"]:
        application = Application(portfolio=portfolio,
                                  name=mock_application["name"],
                                  description="")
        env_names = [env["name"] for env in mock_application["environments"]]
        envs = Environments.create_many(portfolio.owner, application,
                                        env_names)
        db.session.add(application)
        db.session.commit()