def task_order(): user = UserFactory.create() portfolio = PortfolioFactory.create(owner=user) task_order = TaskOrderFactory.create(portfolio=portfolio) CLINFactory.create(task_order=task_order) return task_order
def test_clin_sorting(): task_order = TaskOrderFactory.create(clins=[ CLINFactory.create(number="0002"), CLINFactory.create(number="0001"), CLINFactory.create(number="1001"), CLINFactory.create(number="1002"), CLINFactory.create(number="2001"), ]) assert [clin.number for clin in task_order.sorted_clins] == [ "0001", "1001", "2001", "0002", "1002", ]
def test_task_order_sort_by_status(): today = date.today() yesterday = today - timedelta(days=1) future = today + timedelta(days=100) initial_to_list = [ # Draft TaskOrderFactory.create(pdf=None), TaskOrderFactory.create(pdf=None), TaskOrderFactory.create(pdf=None), # Active TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=yesterday, end_date=future)], ), # Upcoming TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=future, end_date=future)], ), # Expired TaskOrderFactory.create( signed_at=yesterday, clins=[ CLINFactory.create(start_date=yesterday, end_date=yesterday) ], ), TaskOrderFactory.create( signed_at=yesterday, clins=[ CLINFactory.create(start_date=yesterday, end_date=yesterday) ], ), # Unsigned TaskOrderFactory.create( clins=[CLINFactory.create(start_date=today, end_date=today)]), ] sorted_by_status = TaskOrders.sort_by_status(initial_to_list) assert len(sorted_by_status["Draft"]) == 3 assert len(sorted_by_status["Active"]) == 1 assert len(sorted_by_status["Upcoming"]) == 1 assert len(sorted_by_status["Expired"]) == 2 assert len(sorted_by_status["Unsigned"]) == 1 assert list( sorted_by_status.keys()) == [status.value for status in SORT_ORDERING]
def test_period_of_performance_is_first_to_last_clin(): start_date = date(2019, 6, 6) end_date = date(2020, 6, 6) intermediate_start_date = date(2019, 7, 1) intermediate_end_date = date(2020, 3, 1) task_order = TaskOrderFactory.create(clins=[ CLINFactory.create(start_date=intermediate_start_date, end_date=intermediate_end_date), CLINFactory.create(start_date=start_date, end_date=intermediate_end_date), CLINFactory.create(start_date=intermediate_start_date, end_date=intermediate_end_date), CLINFactory.create(start_date=intermediate_start_date, end_date=end_date), CLINFactory.create(start_date=intermediate_start_date, end_date=intermediate_end_date), ]) assert task_order.start_date == start_date assert task_order.end_date == end_date
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
def test_task_order_sorting(): """ Task orders should be listed first by status, and then by time_created. """ today = date.today() yesterday = today - timedelta(days=1) future = today + timedelta(days=100) task_orders = [ # Draft TaskOrderFactory.create(pdf=None), TaskOrderFactory.create(pdf=None), TaskOrderFactory.create(pdf=None), # Active TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=yesterday, end_date=future)], ), TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=yesterday, end_date=future)], ), TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=yesterday, end_date=future)], ), # Upcoming TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=future, end_date=future)], ), TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=future, end_date=future)], ), TaskOrderFactory.create( signed_at=yesterday, clins=[CLINFactory.create(start_date=future, end_date=future)], ), # Expired TaskOrderFactory.create( signed_at=yesterday, clins=[ CLINFactory.create(start_date=yesterday, end_date=yesterday) ], ), TaskOrderFactory.create( signed_at=yesterday, clins=[ CLINFactory.create(start_date=yesterday, end_date=yesterday) ], ), TaskOrderFactory.create( signed_at=yesterday, clins=[ CLINFactory.create(start_date=yesterday, end_date=yesterday) ], ), # Unsigned TaskOrderFactory.create( clins=[CLINFactory.create(start_date=today, end_date=today)]), TaskOrderFactory.create( clins=[CLINFactory.create(start_date=today, end_date=today)]), TaskOrderFactory.create( clins=[CLINFactory.create(start_date=today, end_date=today)]), ] assert TaskOrders.sort(task_orders) == task_orders
def test_task_order_clins_are_completed(): assert TaskOrderFactory.create( clins=[CLINFactory.create()]).clins_are_completed assert not TaskOrderFactory.create().clins_are_completed assert not TaskOrderFactory.create(clins=[]).clins_are_completed
def test_task_order_completed(): assert TaskOrderFactory.create(clins=[CLINFactory.create()]).is_completed assert not TaskOrderFactory.create().is_completed assert not TaskOrderFactory.create(clins=[]).is_completed assert not TaskOrderFactory.create(number=None).is_completed