53 lines
1.3 KiB
Python
53 lines
1.3 KiB
Python
import datetime
|
|
|
|
from django.test import TestCase
|
|
from django.db import models
|
|
from django.utils import timezone
|
|
|
|
from lostplaces_app.models import Voucher
|
|
from lostplaces_app.tests.models import ModelTestCase
|
|
|
|
|
|
def mock_voucher():
|
|
return Voucher.objects.create(
|
|
code='ayDraJCCwfhcFiYmSR5GrcjcchDfcahv',
|
|
expires_when=timezone.now() + datetime.timedelta(days=1)
|
|
)
|
|
|
|
|
|
class VoucherTestCase(ModelTestCase, TestCase):
|
|
model_name = 'Voucher'
|
|
|
|
def setUp(self):
|
|
self.object = mock_voucher()
|
|
|
|
def test_voucher_code(self):
|
|
self._test_char_field(
|
|
'code',
|
|
10,
|
|
100,
|
|
must_have={'unique': True}
|
|
)
|
|
|
|
def test_voucher_created(self):
|
|
self._test_field(
|
|
'created_when',
|
|
models.DateTimeField,
|
|
must_have={'auto_now_add': True}
|
|
)
|
|
|
|
def test_voucher_expires(self):
|
|
self._test_field(
|
|
'expires_when',
|
|
models.DateTimeField,
|
|
must_not_have={'auto_now_add': True}
|
|
)
|
|
|
|
def test_str(self):
|
|
voucher = self.object
|
|
self.assertTrue(voucher.code.lower() in str(voucher).lower(),
|
|
msg='Expecting %s.__str__ to contain the voucher code' % (
|
|
self.model_name
|
|
)
|
|
)
|