def test_delete_portfolio_failure(no_debug_client, user_session): portfolio = PortfolioFactory.create() application = ApplicationFactory.create(portfolio=portfolio) owner = portfolio.owner user_session(owner) assert len(Portfolios.for_user(user=owner)) == 1 response = no_debug_client.post( url_for("portfolios.delete_portfolio", portfolio_id=portfolio.id)) assert response.status_code == 500 assert len(Portfolios.for_user(user=owner)) == 1
def test_delete_portfolio_success(client, user_session): portfolio = PortfolioFactory.create() owner = portfolio.owner user_session(owner) assert len(Portfolios.for_user(user=owner)) == 1 response = client.post( url_for("portfolios.delete_portfolio", portfolio_id=portfolio.id)) assert response.status_code == 302 assert url_for("atst.home") in response.location assert len(Portfolios.for_user(user=owner)) == 0
def test_for_user_does_not_include_deleted_application_roles(): user1 = UserFactory.create() user2 = UserFactory.create() portfolio = PortfolioFactory.create() app = ApplicationFactory.create(portfolio=portfolio) ApplicationRoleFactory.create(status=ApplicationRoleStatus.ACTIVE, user=user1, application=app) assert len(Portfolios.for_user(user1)) == 1 ApplicationRoleFactory.create(status=ApplicationRoleStatus.ACTIVE, user=user2, application=app, deleted=True) assert len(Portfolios.for_user(user2)) == 0
def test_create_portfolio_success(client, user_session): user = UserFactory.create() user_session(user) original_portfolio_count = len(PortfoliosQuery.get_all()) response = client.post( url_for("portfolios.create_portfolio"), data={ "name": "My project name", "description": "My project description", "defense_component": "Air Force, Department of the", }, ) assert response.status_code == 302 assert len(PortfoliosQuery.get_all()) == original_portfolio_count + 1 new_portfolio = Portfolios.for_user(user=user)[-1] assert ( url_for("applications.portfolio_applications", portfolio_id=new_portfolio.id) in response.location ) assert new_portfolio.owner == user
def portfolios(): portfolios = Portfolios.for_user(g.current_user) if portfolios: return render_template("portfolios/index.html", page=5, portfolios=portfolios) else: return render_template("portfolios/blank_slate.html")
def test_for_user_does_not_return_inactive_portfolios(portfolio, portfolio_owner): bob = UserFactory.create() Portfolios.add_member(portfolio, bob) PortfolioFactory.create() bobs_portfolios = Portfolios.for_user(bob) assert len(bobs_portfolios) == 0
def test_for_user_returns_portfolios_for_applications_user_invited_to(): bob = UserFactory.create() portfolio = PortfolioFactory.create() application = ApplicationFactory.create(portfolio=portfolio) ApplicationRoleFactory.create(application=application, user=bob, status=ApplicationRoleStatus.ACTIVE) assert portfolio in Portfolios.for_user(user=bob)
def test_for_user_returns_active_portfolios_for_user(portfolio, portfolio_owner): bob = UserFactory.create() PortfolioRoleFactory.create(user=bob, portfolio=portfolio, status=PortfolioRoleStatus.ACTIVE) PortfolioFactory.create() bobs_portfolios = Portfolios.for_user(bob) assert len(bobs_portfolios) == 1
def test_existing_member_accepts_valid_invite(client, user_session): portfolio = PortfolioFactory.create() user = UserFactory.create() role = PortfolioRoleFactory.create(portfolio=portfolio, user=user, status=PortfolioRoleStatus.PENDING) invite = PortfolioInvitationFactory.create(dod_id=user.dod_id, role=role) # the user does not have access to the portfolio before accepting the invite assert len(Portfolios.for_user(user)) == 0 user_session(user) response = client.get( url_for("portfolios.accept_invitation", portfolio_token=invite.token)) # user is redirected to the portfolio view assert response.status_code == 302 assert (url_for("applications.portfolio_applications", portfolio_id=invite.portfolio.id) in response.headers["Location"]) # the one-time use invite is no longer usable assert invite.is_accepted # the user has access to the portfolio assert len(Portfolios.for_user(user)) == 1
def test_for_user_does_not_include_deleted_portfolios(): user = UserFactory.create() PortfolioFactory.create(owner=user, deleted=True) assert len(Portfolios.for_user(user)) == 0
def test_for_user_returns_all_portfolios_for_ccpo(portfolio, portfolio_owner): sam = UserFactory.create_ccpo() PortfolioFactory.create() sams_portfolios = Portfolios.for_user(sam) assert len(sams_portfolios) == 2
def _portfolios(): if not g.current_user: return {} portfolios = Portfolios.for_user(g.current_user) return {"portfolios": portfolios}