From 93e593e50d5b0a5714d1dfdc32263293b90fc29d Mon Sep 17 00:00:00 2001 From: leigh-mil Date: Mon, 4 Feb 2019 21:49:02 -0500 Subject: [PATCH] Add tests --- tests/routes/portfolios/test_task_orders.py | 51 ++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tests/routes/portfolios/test_task_orders.py b/tests/routes/portfolios/test_task_orders.py index 6bebd3aa..0d3f66df 100644 --- a/tests/routes/portfolios/test_task_orders.py +++ b/tests/routes/portfolios/test_task_orders.py @@ -1,5 +1,6 @@ from flask import url_for import pytest +from datetime import timedelta, date from atst.domain.roles import Roles from atst.models.portfolio_role import Status as PortfolioStatus @@ -16,7 +17,7 @@ from tests.utils import captured_templates class TestPortfolioFunding: - def test_unfunded_portfolio(self, app, user_session): + def test_portfolio_with_no_task_orders(self, app, user_session): portfolio = PortfolioFactory.create() user_session(portfolio.owner) @@ -66,6 +67,54 @@ class TestPortfolioFunding: assert context["funding_end_date"] is end_date assert context["total_balance"] == active_to1.budget + active_to2.budget + def test_expiring_and_funded_portfolio(self, app, user_session): + portfolio = PortfolioFactory.create() + user_session(portfolio.owner) + + expiring_to = TaskOrderFactory.create( + portfolio=portfolio, + start_date=random_past_date(), + end_date=(date.today() + timedelta(days=10)), + number="42", + ) + active_to = TaskOrderFactory.create( + portfolio=portfolio, + start_date=random_past_date(), + end_date=random_future_date(year_min=1, year_max=2), + number="43", + ) + + with captured_templates(app) as templates: + response = app.test_client().get( + url_for("portfolios.portfolio_funding", portfolio_id=portfolio.id) + ) + + assert response.status_code == 200 + _, context = templates[0] + assert context["funding_end_date"] is active_to.end_date + assert context["funded"] == True + + def test_expiring_and_unfunded_portfolio(self, app, user_session): + portfolio = PortfolioFactory.create() + user_session(portfolio.owner) + + expiring_to = TaskOrderFactory.create( + portfolio=portfolio, + start_date=random_past_date(), + end_date=(date.today() + timedelta(days=10)), + number="42", + ) + + with captured_templates(app) as templates: + response = app.test_client().get( + url_for("portfolios.portfolio_funding", portfolio_id=portfolio.id) + ) + + assert response.status_code == 200 + _, context = templates[0] + assert context["funding_end_date"] is expiring_to.end_date + assert context["funded"] == False + def test_ko_can_view_task_order(client, user_session): portfolio = PortfolioFactory.create()