Ejemplo n.º 1
0
def test_current_fresh_check_made_after_stale_check_does_not_require_update():
    stale_check = factories.StaleTransactionCheckFactory.create()
    fresh_check = factories.TransactionCheckFactory.create(
        transaction=stale_check.transaction, )

    assert_fresh(fresh_check)
    assert_current(fresh_check)
    assert_requires_update(fresh_check, False)
Ejemplo n.º 2
0
def test_check_after_stale_check_in_other_workbasket_does_not_require_update():
    stale_check = factories.StaleTransactionCheckFactory.create()
    after_check = factories.TransactionCheckFactory.create(
        transaction__partition=stale_check.transaction.partition,
        transaction__order=stale_check.transaction.order + 1,
    )
    assert after_check.transaction.workbasket != stale_check.transaction.workbasket

    assert_fresh(after_check)
    assert_current(after_check)
    assert_requires_update(after_check, False)
Ejemplo n.º 3
0
def test_current_fresh_check_made_on_transaction_after_updated_stale_check_does_not_require_update(
):
    stale_check = factories.StaleTransactionCheckFactory.create()
    fresh_check = factories.TransactionCheckFactory.create(
        transaction=stale_check.transaction, )
    assert_requires_update(fresh_check, False)

    after_check = factories.TransactionCheckFactory.create(
        transaction__partition=stale_check.transaction.partition,
        transaction__order=stale_check.transaction.order + 1,
    )

    assert_requires_update(after_check, False)
Ejemplo n.º 4
0
def test_current_fresh_check_made_on_transaction_after_stale_check_requires_update(
):
    stale_check = factories.StaleTransactionCheckFactory.create()
    after_check = factories.TransactionCheckFactory.create(
        transaction__partition=stale_check.transaction.partition,
        transaction__order=stale_check.transaction.order + 1,
        transaction__workbasket=stale_check.transaction.workbasket,
    )
    assert after_check.transaction.workbasket == stale_check.transaction.workbasket

    assert_fresh(after_check)
    assert_current(after_check)
    assert_requires_update(after_check, True)
Ejemplo n.º 5
0
def test_detecting_of_transactions_to_update():
    head_transaction = common_factories.ApprovedTransactionFactory.create()

    # Transaction with no check
    no_check = common_factories.UnapprovedTransactionFactory.create()

    # Transaction that does not require update
    no_update = factories.TransactionCheckFactory.create(
        head_transaction=head_transaction,
    )
    assert_requires_update(no_update, False)

    # Transaction that requires update in DRAFT
    draft_update = factories.StaleTransactionCheckFactory.create(
        transaction__partition=TransactionPartition.DRAFT,
        head_transaction=head_transaction,
    )
    assert_requires_update(draft_update, True)

    # Transaction that requires update in REVISION
    revision_update = factories.StaleTransactionCheckFactory.create(
        transaction__partition=TransactionPartition.REVISION,
        transaction__order=-(head_transaction.order),
        head_transaction=head_transaction,
    )
    assert_requires_update(revision_update, True)

    expected_transaction_ids = {no_check.id, draft_update.transaction.id}

    # The task will replace itself with a new workflow. Testing this is hard.
    # Instead, we will capture the new workflow and assert it is calling the
    # right things. This is brittle but probably better than nothing.
    with mock.patch("celery.app.task.Task.replace", new=lambda _, t: t):
        workflow = tasks.update_checks()  # type: ignore

    assert set(t.task for t in workflow.tasks) == {tasks.check_transaction.name}
    assert set(t.args[0] for t in workflow.tasks) == expected_transaction_ids
Ejemplo n.º 6
0
def test_current_fresh_check_does_not_require_update():
    check = factories.TransactionCheckFactory.create()

    assert_current(check)
    assert_fresh(check)
    assert_requires_update(check, False)
Ejemplo n.º 7
0
def test_check_with_no_models_does_not_require_update():
    check = factories.TransactionCheckFactory.create(empty=True)

    assert_fresh(check)
    assert_current(check)
    assert_requires_update(check, False)
Ejemplo n.º 8
0
def test_stale_check_does_require_update():
    stale_check = factories.StaleTransactionCheckFactory.create()

    assert_current(stale_check)
    assert_requires_update(stale_check, True)