Esempio n. 1
0
def test_funding_duration(session):
    # portfolio with active task orders
    portfolio = PortfolioFactory()

    funding_start_date = random_past_date()
    funding_end_date = random_future_date(year_min=2)

    TaskOrderFactory.create(
        signed_at=random_past_date(),
        portfolio=portfolio,
        create_clins=[{
            "start_date": funding_start_date,
            "end_date": random_future_date(year_max=1),
        }],
    )
    TaskOrderFactory.create(
        portfolio=portfolio,
        signed_at=random_past_date(),
        create_clins=[{
            "start_date": datetime.datetime.now(),
            "end_date": funding_end_date,
        }],
    )

    assert portfolio.funding_duration == (funding_start_date, funding_end_date)

    # empty portfolio
    empty_portfolio = PortfolioFactory()
    assert empty_portfolio.funding_duration == (None, None)
Esempio n. 2
0
def test_get_task_order_found(client):
    TaskOrderFactory.create(id=1, number=1)

    response = client.get('/task-order/1')
    json = response.get_json()

    assert response.status_code == 200
    assert json['id'] == 1
    assert json['number'] == '1'
Esempio n. 3
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
Esempio n. 4
0
    def test_draft_status(self, is_signed, is_completed):
        # Given that I have a TO that is neither completed nor signed
        to = TaskOrderFactory.create()
        is_signed.return_value = False
        is_completed.return_value = False

        assert to.status == Status.DRAFT
Esempio n. 5
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
Esempio n. 6
0
def test_update_adds_clins():
    task_order = TaskOrderFactory.create(number="1231231234")
    to_number = task_order.number
    clins = [
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "12312",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "12312",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
    ]
    task_order = TaskOrders.create(
        creator=task_order.creator,
        portfolio_id=task_order.portfolio_id,
        number="0000000000",
        clins=clins,
        pdf={
            "filename": "sample.pdf",
            "object_name": "1234567"
        },
    )
    assert task_order.number != to_number
    assert len(task_order.clins) == 2
Esempio n. 7
0
def test_days_remaining(session):
    # portfolio with task orders
    funding_end_date = random_future_date(year_min=2)
    portfolio = PortfolioFactory()
    TaskOrderFactory.create(
        portfolio=portfolio,
        signed_at=random_past_date(),
        create_clins=[{
            "end_date": funding_end_date
        }],
    )

    assert (portfolio.days_to_funding_expiration == (
        funding_end_date - datetime.date.today()).days)

    # empty portfolio
    empty_portfolio = PortfolioFactory()
    assert empty_portfolio.days_to_funding_expiration == 0
Esempio n. 8
0
def completed_task_order():
    portfolio = PortfolioFactory.create()
    task_order = TaskOrderFactory.create(
        portfolio=portfolio,
        create_clins=[{
            "number": "1234567890123456789012345678901234567890123"
        }],
    )

    return task_order
Esempio n. 9
0
def test_task_orders_edit_redirects_to_latest_incomplete_step(
        client, user_session, portfolio, to_factory_args, expected_step):
    task_order = TaskOrderFactory.create(portfolio=portfolio,
                                         **to_factory_args)
    user_session(portfolio.owner)

    response = client.get(
        url_for("task_orders.edit", task_order_id=task_order.id))

    assert expected_step in response.location
Esempio n. 10
0
    def test_upcoming_status(self, is_signed, is_completed, start_date,
                             end_date):
        # Given that I have a signed TO and today is before its start_date
        to = TaskOrderFactory.create()
        start_date.return_value = pendulum.today().add(days=1).date()
        end_date.return_value = pendulum.today().add(days=2).date()
        is_signed.return_value = True
        is_completed.return_value = True

        # Its status should be upcoming
        assert to.status == Status.UPCOMING
Esempio n. 11
0
def test_task_orders_submit_form_step_one_add_pdf_delete_pdf(
        client, user_session, portfolio):
    user_session(portfolio.owner)
    task_order = TaskOrderFactory.create(portfolio=portfolio)
    response = client.post(
        url_for("task_orders.submit_form_step_one_add_pdf",
                task_order_id=task_order.id),
        data=build_pdf_form_data(filename="", object_name=""),
    )
    assert task_order.pdf is None
    assert response.status_code == 302
Esempio n. 12
0
def test_task_orders_submit_form_step_one_add_pdf_existing_to(
        client, user_session):
    task_order = TaskOrderFactory.create()
    user_session(task_order.creator)
    response = client.post(
        url_for("task_orders.submit_form_step_one_add_pdf",
                task_order_id=task_order.id),
        data=build_pdf_form_data(),
    )
    assert response.status_code == 302
    assert task_order.pdf.filename == "sample.pdf"
Esempio n. 13
0
def test_portfolio_reports(client, user_session):
    portfolio = PortfolioFactory.create(
        applications=[
            {"name": "application1", "environments": [{"name": "application1 prod"}]}
        ]
    )
    task_order = TaskOrderFactory.create(number="42", portfolio=portfolio)
    user_session(portfolio.owner)
    response = client.get(url_for("portfolios.reports", portfolio_id=portfolio.id))
    assert response.status_code == 200
    assert portfolio.name in response.data.decode()
Esempio n. 14
0
    def test_expired_status(self, is_signed, is_completed, end_date,
                            start_date):
        # Given that I have a signed TO and today is after its expiration date
        to = TaskOrderFactory.create()
        end_date.return_value = pendulum.today().subtract(days=1).date()
        start_date.return_value = pendulum.today().subtract(days=2).date()
        is_signed.return_value = True
        is_completed.return_value = True

        # Its status should be expired
        assert to.status == Status.EXPIRED
Esempio n. 15
0
def test_cancel_edit_causes_to_to_be_deleted(client, user_session, session):
    task_order = TaskOrderFactory.create()
    user_session(task_order.portfolio.owner)
    response = client.post(
        url_for("task_orders.cancel_edit",
                task_order_id=task_order.id,
                save=False),
        data={},
    )
    assert response.status_code == 302

    # TO should be deleted
    assert session.query(TaskOrder).get(task_order.id) is None
Esempio n. 16
0
    def test_active_status(self, is_signed, is_completed, start_date,
                           end_date):
        # Given that I have a signed TO and today is within its start_date and end_date
        today = pendulum.today().date()
        to = TaskOrderFactory.create()

        start_date.return_value = today.subtract(days=1)
        end_date.return_value = today.add(days=1)
        is_signed.return_value = True
        is_completed.return_value = True

        # Its status should be active
        assert to.status == Status.ACTIVE
Esempio n. 17
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)
Esempio n. 18
0
def test_delete_task_order_with_clins(session):
    task_order = TaskOrderFactory.create(create_clins=[{
        "number": 1
    }, {
        "number": 2
    }, {
        "number": 3
    }])
    TaskOrders.delete(task_order.id)

    assert not session.query(
        session.query(TaskOrder).filter_by(
            id=task_order.id).exists()).scalar()
Esempio n. 19
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]
Esempio n. 20
0
    def test_active_status(self, is_signed, is_completed, start_date,
                           end_date):
        today = pendulum.today(tz="UTC").date()

        is_signed.return_value = True
        is_completed.return_value = True

        # Given that I have a signed TO and today is within its start_date and end_date
        to_1 = TaskOrderFactory.create()
        start_date.return_value = today.subtract(days=1)
        end_date.return_value = today.add(days=1)

        # Its status should be active
        assert to_1.status == Status.ACTIVE

        # A period of performance's start and end dates are inclusive, so a TO
        # should be active on its start and end dates
        to_2 = TaskOrderFactory.create()
        start_date.return_value = today
        end_date.return_value = today
        is_signed.return_value = True
        is_completed.return_value = True

        assert to_2.status == Status.ACTIVE
Esempio n. 21
0
def test_cancel_edit_and_save_with_invalid_input_does_not_flash(
        app, client, user_session, session):
    task_order = TaskOrderFactory.create()
    user_session(task_order.portfolio.owner)

    bad_data = {"clins-0-jedi_clin_type": "foo"}

    response = client.post(
        url_for("task_orders.cancel_edit",
                task_order_id=task_order.id,
                save=True),
        data=bad_data,
    )

    assert len(get_flashed_messages()) == 0
Esempio n. 22
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",
    ]
Esempio n. 23
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)
Esempio n. 24
0
def test_task_orders_submit_form_step_two_enforces_unique_number(
        client, user_session, task_order, session):
    number = "1234567890123"
    dupe_task_order = TaskOrderFactory.create(number=number)
    portfolio = task_order.portfolio
    user_session(task_order.portfolio.owner)
    form_data = {"number": number}
    session.begin_nested()
    response = client.post(
        url_for("task_orders.submit_form_step_two_add_number",
                task_order_id=task_order.id),
        data=form_data,
    )
    session.rollback()

    assert response.status_code == 400
Esempio n. 25
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
Esempio n. 26
0
def test_update_does_not_duplicate_clins():
    task_order = TaskOrderFactory.create(number="3453453456",
                                         create_clins=[{
                                             "number": "123"
                                         }, {
                                             "number": "456"
                                         }])
    clins = [
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "123",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
        {
            "jedi_clin_type": "JEDI_CLIN_1",
            "number": "111",
            "start_date": date(2020, 1, 1),
            "end_date": date(2021, 1, 1),
            "obligated_amount": Decimal("5000"),
            "total_amount": Decimal("10000"),
        },
    ]
    task_order = TaskOrders.update(
        task_order_id=task_order.id,
        number="0000000000",
        clins=clins,
        pdf={
            "filename": "sample.pdf",
            "object_name": "1234567"
        },
    )
    assert len(task_order.clins) == 2
    for clin in task_order.clins:
        assert clin.number != "456"
Esempio n. 27
0
def task_order():
    return TaskOrderFactory.create()
Esempio n. 28
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
Esempio n. 29
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
Esempio n. 30
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