Code

Ticket #6141: test.diff

File test.diff, 1.1 KB (added by Doug Van Horn, 6 years ago)

Patches the unit test to expose the problem.

Line 
1Index: tests/modeltests/basic/models.py
2===================================================================
3--- tests/modeltests/basic/models.py    (revision 6897)
4+++ tests/modeltests/basic/models.py    (working copy)
5@@ -390,3 +390,24 @@
6 >>> Article.objects.get(pk=a.id).headline
7 u'\u6797\u539f \u3081\u3050\u307f'
8 """
9+
10+# Create another Article class to test __year queries on a DateField.
11+class Article2(models.Model):
12+    headline = models.CharField(max_length=100, default='No title given.')
13+    pub_date = models.DateField()
14+
15+    class Meta:
16+        ordering = ('pub_date', 'headline')
17+
18+    def __unicode__(self):
19+        return self.headline
20+__test__['API_TESTS'] += """
21+
22+# Edge-case test: A year lookup on a DateField should retrieve all
23+# objects in the give year, including Jan. 1 and Dec. 31.
24+>>> from datetime import date
25+>>> a2_1 = Article2.objects.create(headline='Article2 1', pub_date=date(2008, 1, 1))
26+>>> a2_2 = Article2.objects.create(headline='Article2 2', pub_date=date(2008, 12, 31))
27+>>> Article2.objects.filter(pub_date__year=2008)
28+[<Article2: Article2 1>, <Article2: Article2 2>]
29+"""