예제 #1
0
def test_cart_voucher_form_voucher_not_applicable(voucher,
                                                  request_cart_with_item):
    voucher.min_amount_spent = 200
    voucher.save()
    form = CartVoucherForm({'voucher': voucher.code},
                           instance=request_cart_with_item)
    assert not form.is_valid()
    assert 'voucher' in form.errors
예제 #2
0
def test_cart_voucher_form_active_queryset_voucher_active(
        voucher, request_cart_with_item):
    assert Voucher.objects.count() == 1
    voucher.start_date = datetime.date.today()
    voucher.save()
    form = CartVoucherForm({'voucher': voucher.code},
                           instance=request_cart_with_item)
    qs = form.fields['voucher'].queryset
    assert qs.count() == 1
예제 #3
0
def test_cart_voucher_form_active_queryset_after_some_time(
        voucher, request_cart_with_item):
    assert Voucher.objects.count() == 1
    voucher.start_date = datetime.date(year=2016, month=6, day=1)
    voucher.end_date = datetime.date(year=2016, month=6, day=2)
    voucher.save()

    with freeze_time('2016-05-31'):
        form = CartVoucherForm({'voucher': voucher.code},
                               instance=request_cart_with_item)
        assert form.fields['voucher'].queryset.count() == 0

    with freeze_time('2016-06-01'):
        form = CartVoucherForm({'voucher': voucher.code},
                               instance=request_cart_with_item)
        assert form.fields['voucher'].queryset.count() == 1

    with freeze_time('2016-06-03'):
        form = CartVoucherForm({'voucher': voucher.code},
                               instance=request_cart_with_item)
        assert form.fields['voucher'].queryset.count() == 0
예제 #4
0
def test_cart_voucher_form_invalid_voucher_code(monkeypatch,
                                                request_cart_with_item):
    form = CartVoucherForm({'voucher': 'invalid'},
                           instance=request_cart_with_item)
    assert not form.is_valid()
    assert 'voucher' in form.errors