Skip to content

Commit c27486a

Browse files
committed
Adding a first test
Conflicts: elevennote/note/models.py
1 parent 8674a85 commit c27486a

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

elevennote/note/models.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ class Note(models.Model):
1616
pub_date = models.DateTimeField('date published')
1717

1818
def was_published_recently(self):
19-
return self.pub_date >= timezone.now() - timedelta(days=1)
19+
now = timezone.now()
20+
return now - timedelta(days=1) <= self.pub_date <= now
2021

2122

2223
# Make a tastypie API key whenever a new user is created.

elevennote/note/tests.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,18 @@
1+
import datetime
2+
3+
from django.utils import timezone
14
from django.test import TestCase
25

6+
from .models import Note
7+
38
# Create your tests here.
9+
class NoteMethodTests(TestCase):
10+
11+
def test_was_published_recently(self):
12+
"""
13+
was_published_recently() should return False for notes whose
14+
pub_date is in the future.
15+
"""
16+
time = timezone.now() + datetime.timedelta(days=30)
17+
future_note = Note(pub_date=time)
18+
self.assertEqual(future_note.was_published_recently(), False)

0 commit comments

Comments
 (0)