Testing is_expired

This commit is contained in:
reverend 2020-10-04 22:12:24 +02:00
parent cfbe54a4e5
commit ae915681ac
2 changed files with 36 additions and 4 deletions

View File

@ -2,11 +2,9 @@
# -*- coding: utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from django.core.exceptions import FieldDoesNotExist
from django.test import TestCase
# Creating a test user
class ModelTestCase(TestCase):
'''

View File

@ -1,6 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import datetime
from django.utils import timezone
from django.test import TestCase
from django.db import models
from django.contrib.auth.models import User
@ -10,7 +13,8 @@ from lostplaces.models import (
Mapable,
Submittable,
PlaceAsset,
Expireable
Expireable,
Voucher
)
from lostplaces.tests.models import ModelTestCase
@ -112,4 +116,34 @@ class PlaceAssetTestCase(ModelTestCase):
)
class ExpireableTestCase(ModelTestCase):
model = Expireable
model = Expireable
def test_fields(self):
self.assertField(
field_name='created_when',
field_class=models.DateTimeField,
must_have={'auto_now_add': True}
)
self.assertField(
field_name='expires_when',
field_class=models.DateTimeField
)
def test_is_expired(self):
valid_voucher = Voucher.objects.create(
code='Test123',
expires_when=timezone.now() + datetime.timedelta(minutes=2)
)
self.assertFalse(
valid_voucher.is_expired,
msg='Expecing the expirable object to not be expired'
)
invalid_voucher = Voucher.objects.create(
code='Test1234',
expires_when=timezone.now() - datetime.timedelta(minutes=2)
)
self.assertTrue(
invalid_voucher.is_expired,
msg='Expecing the expirable object to be expired'
)