Beispiel #1
0
def test_change_quantity_generates_proper_event(
    previous_quantity,
    new_quantity,
    added_count,
    removed_count,
    order_with_lines,
    staff_user,
):

    assert not OrderEvent.objects.exists()

    line = order_with_lines.lines.last()
    line.quantity = previous_quantity

    change_order_line_quantity(staff_user, line, previous_quantity, new_quantity)

    if removed_count:
        expected_type = OrderEvents.DRAFT_REMOVED_PRODUCTS
        expected_quantity = removed_count
    elif added_count:
        expected_type = OrderEvents.DRAFT_ADDED_PRODUCTS
        expected_quantity = added_count
    else:
        # No event should have occurred
        assert not OrderEvent.objects.exists()
        return

    new_event = OrderEvent.objects.last()  # type: OrderEvent
    assert new_event.type == expected_type
    assert new_event.user == staff_user
    assert new_event.parameters == {
        "lines": [
            {"quantity": expected_quantity, "line_pk": line.pk, "item": str(line)}
        ]
    }
Beispiel #2
0
def test_order_weight_change_line_quantity(order_with_lines):
    line = order_with_lines.lines.first()
    new_quantity = line.quantity + 2
    change_order_line_quantity(None, line, new_quantity, line.quantity)
    order_with_lines.refresh_from_db()
    assert order_with_lines.weight == _calculate_order_weight_from_lines(
        order_with_lines)
def test_change_quantity_generates_proper_event(
    previous_quantity,
    new_quantity,
    added_count,
    removed_count,
    order_with_lines,
    staff_user,
):

    assert not OrderEvent.objects.exists()

    line = order_with_lines.lines.last()
    line.quantity = previous_quantity

    change_order_line_quantity(staff_user, line, previous_quantity, new_quantity)

    if removed_count:
        expected_type = OrderEvents.DRAFT_REMOVED_PRODUCTS
        expected_quantity = removed_count
    elif added_count:
        expected_type = OrderEvents.DRAFT_ADDED_PRODUCTS
        expected_quantity = added_count
    else:
        # No event should have occurred
        assert not OrderEvent.objects.exists()
        return

    new_event = OrderEvent.objects.last()  # type: OrderEvent
    assert new_event.type == expected_type
    assert new_event.user == staff_user
    assert new_event.parameters == {
        "lines": [{"quantity": expected_quantity, "item": str(line)}]
    }
Beispiel #4
0
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
    assert list(order_with_lines.history.all()) == []
    lines = order_with_lines.groups.all()[0].lines.all()
    for line in lines:
        change_order_line_quantity(line, 0)
    history = list(order_with_lines.history.all())
    assert len(history) == 1
    assert history[0].content == 'Order cancelled. No items in order'
Beispiel #5
0
def test_order_weight_change_line_quantity(order_with_lines):
    line = order_with_lines.lines.first()
    new_quantity = line.quantity + 2
    change_order_line_quantity(None, line, new_quantity, line.quantity)
    order_with_lines.refresh_from_db()
    assert order_with_lines.weight == _calculate_order_weight_from_lines(
        order_with_lines
    )
Beispiel #6
0
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
    assert list(order_with_lines.history.all()) == []
    lines = order_with_lines.lines.all()
    change_order_line_quantity(lines[2], 0)
    change_order_line_quantity(lines[1], 0)
    change_order_line_quantity(lines[0], 0)
    assert order_with_lines.get_total_quantity() == 0
Beispiel #7
0
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
    assert list(order_with_lines.history.all()) == []
    lines = order_with_lines.lines.all()
    change_order_line_quantity(lines[2], 0)
    change_order_line_quantity(lines[1], 0)
    change_order_line_quantity(lines[0], 0)
    assert order_with_lines.get_total_quantity() == 0
Beispiel #8
0
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
    assert list(order_with_lines.history.all()) == []
    lines = order_with_lines.groups.all()[0].lines.all()
    change_order_line_quantity(lines[0], 0)
    change_order_line_quantity(lines[1], 0)
    change_order_line_quantity(lines[2], 0)
    history = list(order_with_lines.history.all())
    assert len(history) == 1
    assert history[0].content == 'Order cancelled. No items in order'
Beispiel #9
0
def test_ordered_item_change_quantity(transactional_db, order_with_items):
    assert list(order_with_items.history.all()) == []
    items = order_with_items.groups.all()[0].items.all()
    change_order_line_quantity(items[0], 0)
    change_order_line_quantity(items[1], 0)
    change_order_line_quantity(items[2], 0)
    history = list(order_with_items.history.all())
    assert len(history) == 1
    assert history[0].status == 'cancelled'
    assert history[0].comment == 'Order cancelled. No items in order'
Beispiel #10
0
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
    assert not order_with_lines.events.count()
    lines = order_with_lines.lines.all()
    change_order_line_quantity(None, lines[1], lines[1].quantity, 0)
    change_order_line_quantity(None, lines[0], lines[0].quantity, 0)
    assert order_with_lines.get_total_quantity() == 0
Beispiel #11
0
def test_ordered_item_change_quantity(transactional_db, order_with_lines):
    assert not order_with_lines.events.count()
    lines = order_with_lines.lines.all()
    change_order_line_quantity(lines[1], 0)
    change_order_line_quantity(lines[0], 0)
    assert order_with_lines.get_total_quantity() == 0