2018-01-15 16:52:46 +01:00
|
|
|
import datetime
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from django.test import TestCase
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from kfet.forms import KPsulCheckoutForm
|
|
|
|
from kfet.models import Checkout
|
|
|
|
|
|
|
|
from .utils import create_user
|
|
|
|
|
|
|
|
|
|
|
|
class KPsulCheckoutFormTests(TestCase):
|
|
|
|
def setUp(self):
|
|
|
|
self.now = timezone.now()
|
|
|
|
|
|
|
|
user = create_user()
|
|
|
|
|
|
|
|
self.c1 = Checkout.objects.create(
|
2018-10-06 12:35:49 +02:00
|
|
|
name="C1",
|
|
|
|
balance=10,
|
2018-01-15 16:52:46 +01:00
|
|
|
created_by=user.profile.account_kfet,
|
|
|
|
valid_from=self.now,
|
|
|
|
valid_to=self.now + datetime.timedelta(days=1),
|
|
|
|
)
|
|
|
|
|
|
|
|
self.form = KPsulCheckoutForm()
|
|
|
|
|
|
|
|
def test_checkout(self):
|
2018-10-06 12:35:49 +02:00
|
|
|
checkout_f = self.form.fields["checkout"]
|
|
|
|
self.assertListEqual(
|
|
|
|
list(checkout_f.choices), [("", "---------"), (self.c1.pk, "C1")]
|
|
|
|
)
|
2018-01-15 16:52:46 +01:00
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
@mock.patch("django.utils.timezone.now")
|
2018-01-15 16:52:46 +01:00
|
|
|
def test_checkout_valid(self, mock_now):
|
|
|
|
"""
|
|
|
|
Checkout are filtered using the current datetime.
|
|
|
|
Regression test for #184.
|
|
|
|
"""
|
|
|
|
self.now += datetime.timedelta(days=2)
|
|
|
|
mock_now.return_value = self.now
|
|
|
|
|
|
|
|
form = KPsulCheckoutForm()
|
|
|
|
|
2018-10-06 12:35:49 +02:00
|
|
|
checkout_f = form.fields["checkout"]
|
|
|
|
self.assertListEqual(list(checkout_f.choices), [("", "---------")])
|