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 @@ -14,4 +14,5 @@ class Note(models.Model):
14
14
pub_date = models .DateTimeField ('date published' )
15
15
16
16
def was_published_recently (self ):
17
- return self .pub_date >= timezone .now () - timedelta (days = 1 )
17
+ now = timezone .now ()
18
+ return now - timedelta (days = 1 ) <= self .pub_date <= now
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