Currently, we use both Python's built-in datetime library and Pendulum to do datetime operations. For the sake of consistency, we should try to stick to one library for datetimes. We could have used either, but Pendulum has a more ergonomic API, so I decided to go with it when possible. The places where were we didn't / couldn't replace datetime are: - checking instances of datetimes. Pendulum's objects are subclasses of python native datetime objects, so it's still useful to import datetime in those cases of using is_instance() - WTForms date validators expect datetime style string formats -- Pendulum has its own format for formatting/ parsing strings. As such, our custom validator DateRange needs to use datetime.stptime() to account for this format.
55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
from flask import url_for
|
|
import pytest
|
|
|
|
from atst.domain.permission_sets import PermissionSets
|
|
from atst.domain.task_orders import TaskOrders
|
|
from atst.models import *
|
|
from atst.models.portfolio_role import Status as PortfolioStatus
|
|
from atst.models.task_order import Status as TaskOrderStatus
|
|
from atst.utils.localization import translate
|
|
|
|
from tests.factories import *
|
|
from tests.utils import captured_templates
|
|
|
|
|
|
@pytest.fixture
|
|
def portfolio():
|
|
return PortfolioFactory.create()
|
|
|
|
|
|
@pytest.fixture
|
|
def user():
|
|
return UserFactory.create()
|
|
|
|
|
|
@pytest.fixture
|
|
def task_order():
|
|
user = UserFactory.create()
|
|
portfolio = PortfolioFactory.create(owner=user)
|
|
attachment = Attachment(filename="sample_attachment", object_name="sample")
|
|
task_order = TaskOrderFactory.create(portfolio=portfolio)
|
|
CLINFactory.create(task_order=task_order)
|
|
|
|
return task_order
|
|
|
|
|
|
def test_view_task_order_not_draft(client, user_session, task_order):
|
|
TaskOrders.sign(task_order=task_order, signer_dod_id=random_dod_id())
|
|
user_session(task_order.portfolio.owner)
|
|
response = client.get(
|
|
url_for("task_orders.view_task_order", task_order_id=task_order.id)
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
|
|
def test_view_task_order_draft(client, user_session, task_order):
|
|
TaskOrders.update(
|
|
task_order_id=task_order.id, number="1234567890", clins=[], pdf=None
|
|
)
|
|
user_session(task_order.portfolio.owner)
|
|
response = client.get(
|
|
url_for("task_orders.view_task_order", task_order_id=task_order.id)
|
|
)
|
|
assert response.status_code == 302
|
|
assert url_for("task_orders.edit", task_order_id=task_order.id) in response.location
|