lostplaces-backend/django_lostplaces/lostplaces/tests/models/test_voucher_model.py

47 lines
1.2 KiB
Python
Raw Permalink Normal View History

2020-09-19 22:50:07 +02:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2020-09-11 12:08:27 +02:00
2020-09-19 22:50:07 +02:00
import datetime
2020-09-11 12:08:27 +02:00
from django.test import TestCase
from django.db import models
from django.utils import timezone
2020-09-11 12:08:27 +02:00
from lostplaces.models import Voucher
from lostplaces.tests.models import ModelTestCase
2020-09-11 12:08:27 +02:00
2020-09-21 21:37:28 +02:00
class VoucherTestCase(ModelTestCase):
2020-09-11 23:07:19 +02:00
model = Voucher
@classmethod
def setUpTestData(cls):
Voucher.objects.create(
2020-09-13 19:12:32 +02:00
code='ayDraJCCwfhcFiYmSR5GrcjcchDfcahv',
expires_when=timezone.now() + datetime.timedelta(days=1)
)
def setUp(self):
self.voucher = Voucher.objects.get(id=1)
2020-09-12 08:38:37 +02:00
2020-09-11 12:08:27 +02:00
def test_voucher_code(self):
2020-09-13 13:30:11 +02:00
self.assertCharField(
2020-09-13 19:12:32 +02:00
field_name='code',
min_length=10,
max_length=100,
2020-09-11 12:08:27 +02:00
must_have={'unique': True}
)
def test_voucher_created(self):
2020-09-13 13:29:27 +02:00
self.assertField(
2020-09-13 19:12:32 +02:00
field_name='created_when',
field_class=models.DateTimeField,
2020-09-11 12:08:27 +02:00
must_have={'auto_now_add': True}
)
def test_voucher_expires(self):
2020-09-13 13:29:27 +02:00
self.assertField(
2020-09-13 19:12:32 +02:00
field_name='expires_when',
field_class=models.DateTimeField,
2020-09-11 12:08:27 +02:00
must_not_have={'auto_now_add': True}
)