Testing is_expired
This commit is contained in:
parent
cfbe54a4e5
commit
ae915681ac
@ -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):
|
||||
'''
|
||||
|
@ -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
|
||||
|
||||
@ -113,3 +117,33 @@ class PlaceAssetTestCase(ModelTestCase):
|
||||
|
||||
class ExpireableTestCase(ModelTestCase):
|
||||
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'
|
||||
)
|
Loading…
Reference in New Issue
Block a user