Add booking.models.Duck.age() with tests

This commit is contained in:
Gergely Polonkai 2014-12-17 11:08:13 +01:00 committed by Gergely Polonkai
parent 67dba65b43
commit b114fbfc07
2 changed files with 19 additions and 0 deletions

View File

@ -50,6 +50,15 @@ class Duck(models.Model):
return self.name
def age(self):
seconds_d = timezone.now() - self.donated_at
seconds = seconds_d.total_seconds()
if seconds < 0:
return -1
return seconds
class DuckName(models.Model):
"""Model to hold name suggestions for Ducks"""

View File

@ -1,4 +1,9 @@
from django.test import TestCase, Client
from django.utils import timezone
import datetime
from .models import Duck
class FrontTest(TestCase):
def setUp(self):
@ -15,3 +20,8 @@ class FrontTest(TestCase):
def test_disclaimer_page(self):
response = self.client.get('/disclaimer.html')
self.assertEqual(response.status_code, 200)
class DuckAgeTest(TestCase):
def test_duck_is_from_the_future(self):
future_duck = Duck(donated_at = timezone.now() + datetime.timedelta(days = 2))
self.assertEqual(future_duck.age(), -1)