Add tests for portfolio funding route

This adds a helper to grab a template's context. Using a helper from the
Flask documentation: http://flask.pocoo.org/docs/1.0/signals/?highlight=template_rendered#subscribing-to-signals
This commit is contained in:
Patrick Smith
2019-01-15 21:10:15 -05:00
parent b1348b52e5
commit ba97117a74
4 changed files with 119 additions and 33 deletions

View File

@@ -0,0 +1,62 @@
from flask import url_for
import pytest
from tests.factories import (
PortfolioFactory,
TaskOrderFactory,
random_future_date,
random_past_date,
)
from tests.utils import captured_templates
class TestPortfolioFunding:
def test_unfunded_portfolio(self, app, user_session):
portfolio = PortfolioFactory.create()
user_session(portfolio.owner)
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 None
assert context["total_balance"] == 0
assert context["pending_task_orders"] == []
assert context["active_task_orders"] == []
assert context["expired_task_orders"] == []
def test_funded_portfolio(self, app, user_session):
portfolio = PortfolioFactory.create()
user_session(portfolio.owner)
pending_to = TaskOrderFactory.create(portfolio=portfolio)
active_to1 = TaskOrderFactory.create(
portfolio=portfolio,
start_date=random_past_date(),
end_date=random_future_date(),
number="42",
)
active_to2 = TaskOrderFactory.create(
portfolio=portfolio,
start_date=random_past_date(),
end_date=random_future_date(),
number="43",
)
end_date = (
active_to1.end_date
if active_to1.end_date > active_to2.end_date
else active_to2.end_date
)
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 end_date
assert context["total_balance"] == active_to1.budget + active_to2.budget