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
63 lines
2.1 KiB
Python
63 lines
2.1 KiB
Python
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
|