diff --git a/django_lostplaces/lostplaces/tests/models/__init__.py b/django_lostplaces/lostplaces/tests/models/__init__.py index 1e5f7f6..70b5253 100644 --- a/django_lostplaces/lostplaces/tests/models/__init__.py +++ b/django_lostplaces/lostplaces/tests/models/__init__.py @@ -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): ''' diff --git a/django_lostplaces/lostplaces/tests/models/test_abstract_models.py b/django_lostplaces/lostplaces/tests/models/test_abstract_models.py index 30415de..3d32b25 100644 --- a/django_lostplaces/lostplaces/tests/models/test_abstract_models.py +++ b/django_lostplaces/lostplaces/tests/models/test_abstract_models.py @@ -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 \ No newline at end of file + 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' + ) \ No newline at end of file