示例#1
0
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
示例#2
0
    def test_total_contract_amount(self):
        to = TaskOrderFactory.create()
        assert to.total_contract_amount == 0

        clin1 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_1)
        clin2 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_2)
        clin3 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_3)

        assert (to.total_contract_amount == clin1.total_amount +
                clin2.total_amount + clin3.total_amount)
示例#3
0
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",
    ]
示例#4
0
    def test_total_obligated_funds(self):
        to = TaskOrderFactory.create()
        assert to.total_obligated_funds == 0

        clin1 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_1)
        clin2 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_2)
        clin3 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_3)
        clin4 = CLINFactory(task_order=to,
                            jedi_clin_type=JEDICLINType.JEDI_CLIN_4)
        assert (to.total_obligated_funds == clin1.obligated_amount +
                clin2.obligated_amount + clin3.obligated_amount +
                clin4.obligated_amount)
示例#5
0
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]
示例#6
0
def add_task_orders_to_portfolio(portfolio):
    today = date.today()
    future = today + timedelta(days=100)
    yesterday = today - timedelta(days=1)
    five_days = timedelta(days=5)

    def build_pdf():
        return {
            "filename": "sample_task_order.pdf",
            "object_name": str(uuid4())
        }

    draft_to = TaskOrderFactory.build(portfolio=portfolio, pdf=None)
    unsigned_to = TaskOrderFactory.build(portfolio=portfolio, pdf=build_pdf())
    upcoming_to = TaskOrderFactory.build(portfolio=portfolio,
                                         signed_at=yesterday,
                                         pdf=build_pdf())
    expired_to = TaskOrderFactory.build(portfolio=portfolio,
                                        signed_at=yesterday,
                                        pdf=build_pdf())
    active_to = TaskOrderFactory.build(portfolio=portfolio,
                                       signed_at=yesterday,
                                       pdf=build_pdf())

    clins = [
        CLINFactory.build(task_order=unsigned_to,
                          start_date=(today - five_days),
                          end_date=today),
        CLINFactory.build(task_order=upcoming_to,
                          start_date=future,
                          end_date=(today + five_days)),
        CLINFactory.build(task_order=expired_to,
                          start_date=(today - five_days),
                          end_date=yesterday),
        CLINFactory.build(task_order=active_to,
                          start_date=yesterday,
                          end_date=future),
    ]

    task_orders = [draft_to, unsigned_to, upcoming_to, expired_to, active_to]

    db.session.add_all(task_orders + clins)
    db.session.commit()
示例#7
0
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
示例#8
0
文件: test_new.py 项目: robgil/atst
def test_task_orders_submit_task_order(client, user_session, task_order):
    user_session(task_order.portfolio.owner)
    response = client.post(
        url_for("task_orders.submit_task_order", task_order_id=task_order.id))
    assert response.status_code == 302

    active_start_date = date.today() - timedelta(days=1)
    active_task_order = TaskOrderFactory(portfolio=task_order.portfolio)
    CLINFactory(task_order=active_task_order, start_date=active_start_date)
    assert active_task_order.status == TaskOrderStatus.UNSIGNED
    response = client.post(
        url_for("task_orders.submit_task_order",
                task_order_id=active_task_order.id))
    assert active_task_order.status == TaskOrderStatus.ACTIVE

    upcoming_start_date = date.today() + timedelta(days=1)
    upcoming_task_order = TaskOrderFactory(portfolio=task_order.portfolio)
    CLINFactory(task_order=upcoming_task_order, start_date=upcoming_start_date)
    assert upcoming_task_order.status == TaskOrderStatus.UNSIGNED
    response = client.post(
        url_for("task_orders.submit_task_order",
                task_order_id=upcoming_task_order.id))
    assert upcoming_task_order.status == TaskOrderStatus.UPCOMING
示例#9
0
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
示例#10
0
def add_task_orders_to_portfolio(portfolio):
    today = date.today()
    future = today + timedelta(days=100)
    yesterday = today - timedelta(days=1)
    five_days = timedelta(days=5)

    def build_pdf():
        return {
            "filename": "sample_task_order.pdf",
            "object_name": str(uuid4())
        }

    draft_to = TaskOrderFactory.build(portfolio=portfolio, pdf=None)
    unsigned_to = TaskOrderFactory.build(portfolio=portfolio, pdf=build_pdf())
    upcoming_to = TaskOrderFactory.build(portfolio=portfolio,
                                         signed_at=yesterday,
                                         pdf=build_pdf())
    expired_to = TaskOrderFactory.build(portfolio=portfolio,
                                        signed_at=yesterday,
                                        pdf=build_pdf())
    active_to = TaskOrderFactory.build(portfolio=portfolio,
                                       signed_at=yesterday,
                                       pdf=build_pdf())

    clins = [
        CLINFactory.build(task_order=unsigned_to,
                          start_date=(today - five_days),
                          end_date=today),
        CLINFactory.build(task_order=upcoming_to,
                          start_date=future,
                          end_date=(today + five_days)),
        CLINFactory.build(task_order=expired_to,
                          start_date=(today - five_days),
                          end_date=yesterday),
        CLINFactory.build(
            task_order=active_to,
            start_date=yesterday,
            end_date=future,
            total_amount=1_000_000,
            obligated_amount=500_000,
            jedi_clin_type=JEDICLINType.JEDI_CLIN_1,
        ),
        CLINFactory.build(
            task_order=active_to,
            start_date=yesterday,
            end_date=future,
            total_amount=500_000,
            obligated_amount=200_000,
            jedi_clin_type=JEDICLINType.JEDI_CLIN_2,
        ),
    ]
示例#11
0
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
示例#12
0
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
示例#13
0
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