Portfolio archiving
This commit is contained in:
@@ -2,7 +2,11 @@ import pytest
|
||||
from uuid import uuid4
|
||||
|
||||
from atst.domain.exceptions import NotFoundError, UnauthorizedError
|
||||
from atst.domain.portfolios import Portfolios, PortfolioError
|
||||
from atst.domain.portfolios import (
|
||||
Portfolios,
|
||||
PortfolioError,
|
||||
PortfolioDeletionApplicationsExistError,
|
||||
)
|
||||
from atst.domain.portfolio_roles import PortfolioRoles
|
||||
from atst.domain.applications import Applications
|
||||
from atst.domain.environments import Environments
|
||||
@@ -221,3 +225,25 @@ def test_invite():
|
||||
assert invitation.role.portfolio == portfolio
|
||||
assert invitation.role.user is None
|
||||
assert invitation.dod_id == member_data["dod_id"]
|
||||
|
||||
|
||||
def test_delete_success():
|
||||
portfolio = PortfolioFactory.create()
|
||||
|
||||
assert not portfolio.deleted
|
||||
|
||||
Portfolios.delete(portfolio=portfolio)
|
||||
|
||||
assert portfolio.deleted
|
||||
|
||||
|
||||
def test_delete_failure_with_applications():
|
||||
portfolio = PortfolioFactory.create()
|
||||
application = ApplicationFactory.create(portfolio=portfolio)
|
||||
|
||||
assert not portfolio.deleted
|
||||
|
||||
with pytest.raises(PortfolioDeletionApplicationsExistError):
|
||||
Portfolios.delete(portfolio=portfolio)
|
||||
|
||||
assert not portfolio.deleted
|
||||
|
@@ -3,6 +3,7 @@ from flask import url_for
|
||||
from tests.factories import (
|
||||
random_future_date,
|
||||
random_past_date,
|
||||
ApplicationFactory,
|
||||
PortfolioFactory,
|
||||
TaskOrderFactory,
|
||||
UserFactory,
|
||||
@@ -109,3 +110,35 @@ def test_portfolio_reports_with_mock_portfolio(client, user_session):
|
||||
assert response.status_code == 200
|
||||
assert portfolio.name in response.data.decode()
|
||||
assert "$251,626.00 Total spend to date" in response.data.decode()
|
||||
|
||||
|
||||
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_delete_portfolio_failure(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 = client.post(
|
||||
url_for("portfolios.delete_portfolio", portfolio_id=portfolio.id)
|
||||
)
|
||||
|
||||
assert response.status_code == 500
|
||||
assert len(Portfolios.for_user(user=owner)) == 1
|
||||
|
@@ -570,3 +570,34 @@ def test_applications_application_team_access(get_url_assert_status):
|
||||
get_url_assert_status(ccpo, url, 200)
|
||||
get_url_assert_status(portfolio.owner, url, 200)
|
||||
get_url_assert_status(rando, url, 404)
|
||||
|
||||
|
||||
def test_portfolio_delete_access(post_url_assert_status):
|
||||
rando = UserFactory.create()
|
||||
owner = UserFactory.create()
|
||||
ccpo = UserFactory.create_ccpo()
|
||||
|
||||
post_url_assert_status(
|
||||
ccpo,
|
||||
url_for(
|
||||
"portfolios.delete_portfolio", portfolio_id=PortfolioFactory.create().id
|
||||
),
|
||||
302,
|
||||
)
|
||||
|
||||
post_url_assert_status(
|
||||
owner,
|
||||
url_for(
|
||||
"portfolios.delete_portfolio",
|
||||
portfolio_id=PortfolioFactory.create(owner=owner).id,
|
||||
),
|
||||
302,
|
||||
)
|
||||
|
||||
post_url_assert_status(
|
||||
rando,
|
||||
url_for(
|
||||
"portfolios.delete_portfolio", portfolio_id=PortfolioFactory.create().id
|
||||
),
|
||||
404,
|
||||
)
|
||||
|
Reference in New Issue
Block a user