Merge pull request #1199 from dod-ccpo/reporting-refactor-part-1

Reporting refactor part 1
This commit is contained in:
graham-dds
2019-11-25 16:37:49 -05:00
committed by GitHub
22 changed files with 463 additions and 932 deletions

View File

@@ -1,27 +1,22 @@
from atst.domain.reports import Reports
from tests.factories import PortfolioFactory
from tests.factories import *
def test_portfolio_totals():
portfolio = PortfolioFactory.create()
report = Reports.portfolio_totals(portfolio)
assert report == {"budget": 0, "spent": 0}
# this is sketched in until we do real reporting
# this is sketched out until we do real reporting
def test_monthly_totals():
portfolio = PortfolioFactory.create()
monthly = Reports.monthly_totals(portfolio)
assert not monthly["environments"]
assert not monthly["applications"]
assert not monthly["portfolio"]
pass
# this is sketched in until we do real reporting
def test_cumulative_budget():
portfolio = PortfolioFactory.create()
months = Reports.cumulative_budget(portfolio)
# this is sketched out until we do real reporting
def test_current_obligated_funds():
pass
assert len(months["months"]) >= 12
# this is sketched out until we do real reporting
def test_expired_task_orders():
pass
# this is sketched out until we do real reporting
def test_obligated_funds_by_JEDI_clin():
pass

View File

@@ -289,6 +289,7 @@ class TaskOrderFactory(Base):
)
number = factory.LazyFunction(random_task_order_number)
creator = factory.SubFactory(UserFactory)
signed_at = None
_pdf = factory.SubFactory(AttachmentFactory)
@classmethod

View File

@@ -1,4 +1,12 @@
from tests.factories import ApplicationFactory, PortfolioFactory
from tests.factories import (
ApplicationFactory,
PortfolioFactory,
TaskOrderFactory,
CLINFactory,
random_future_date,
random_past_date,
)
import datetime
def test_portfolio_applications_excludes_deleted():
@@ -7,3 +15,73 @@ def test_portfolio_applications_excludes_deleted():
ApplicationFactory.create(portfolio=portfolio, deleted=True)
assert len(portfolio.applications) == 1
assert portfolio.applications[0].id == app.id
def test_funding_duration(session):
# portfolio with active task orders
portfolio = PortfolioFactory()
funding_start_date = random_past_date()
funding_end_date = random_future_date(year_min=2)
TaskOrderFactory.create(
signed_at=random_past_date(),
portfolio=portfolio,
create_clins=[
{
"start_date": funding_start_date,
"end_date": random_future_date(year_max=1),
}
],
)
TaskOrderFactory.create(
portfolio=portfolio,
signed_at=random_past_date(),
create_clins=[
{"start_date": datetime.datetime.now(), "end_date": funding_end_date,}
],
)
assert portfolio.funding_duration == (funding_start_date, funding_end_date)
# empty portfolio
empty_portfolio = PortfolioFactory()
assert empty_portfolio.funding_duration == (None, None)
def test_days_remaining(session):
# portfolio with task orders
funding_end_date = random_future_date(year_min=2)
portfolio = PortfolioFactory()
TaskOrderFactory.create(
portfolio=portfolio,
signed_at=random_past_date(),
create_clins=[{"end_date": funding_end_date}],
)
assert (
portfolio.days_to_funding_expiration
== (funding_end_date - datetime.date.today()).days
)
# empty portfolio
empty_portfolio = PortfolioFactory()
assert empty_portfolio.days_to_funding_expiration == 0
def test_active_task_orders(session):
portfolio = PortfolioFactory()
TaskOrderFactory.create(
portfolio=portfolio,
signed_at=random_past_date(),
create_clins=[
{
"start_date": datetime.date(2019, 1, 1),
"end_date": datetime.date(2019, 10, 31),
}
],
)
TaskOrderFactory.create(
portfolio=portfolio, signed_at=random_past_date(), clins=[CLINFactory.create()]
)
assert len(portfolio.active_task_orders) == 1

View File

@@ -110,7 +110,6 @@ def test_portfolio_reports_with_mock_portfolio(client, user_session):
response = client.get(url_for("portfolios.reports", portfolio_id=portfolio.id))
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):