File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,8 @@ class Note(models.Model):
16
16
pub_date = models .DateTimeField ('date published' )
17
17
18
18
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
20
21
21
22
22
23
# Make a tastypie API key whenever a new user is created.
Original file line number Diff line number Diff line change
1
+ import datetime
2
+
3
+ from django .utils import timezone
1
4
from django .test import TestCase
2
5
6
+ from .models import Note
7
+
3
8
# 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 )
You can’t perform that action at this time.
0 commit comments