~ubuntu-branches/debian/sid/python-django/sid

« back to all changes in this revision

Viewing changes to tests/regressiontests/dates/tests.py

  • Committer: Package Import Robot
  • Author(s): Luke Faraone
  • Date: 2013-11-07 15:33:49 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131107153349-e31sc149l2szs3jb
Tags: 1.6-1
* New upstream version. Closes: #557474, #724637.
* python-django now also suggests the installation of ipython,
  bpython, python-django-doc, and libgdal1.
  Closes: #636511, #686333, #704203
* Set package maintainer to Debian Python Modules Team.
* Bump standards version to 3.9.5, no changes needed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from __future__ import absolute_import
2
 
 
3
 
from datetime import datetime
4
 
 
5
 
from django.test import TestCase
6
 
 
7
 
from .models import Article, Comment, Category
8
 
 
9
 
 
10
 
class DatesTests(TestCase):
11
 
    def test_related_model_traverse(self):
12
 
        a1 = Article.objects.create(
13
 
            title="First one",
14
 
            pub_date=datetime(2005, 7, 28),
15
 
        )
16
 
        a2 = Article.objects.create(
17
 
            title="Another one",
18
 
            pub_date=datetime(2010, 7, 28),
19
 
        )
20
 
        a3 = Article.objects.create(
21
 
            title="Third one, in the first day",
22
 
            pub_date=datetime(2005, 7, 28),
23
 
        )
24
 
 
25
 
        a1.comments.create(
26
 
            text="Im the HULK!",
27
 
            pub_date=datetime(2005, 7, 28),
28
 
        )
29
 
        a1.comments.create(
30
 
            text="HULK SMASH!",
31
 
            pub_date=datetime(2005, 7, 29),
32
 
        )
33
 
        a2.comments.create(
34
 
            text="LMAO",
35
 
            pub_date=datetime(2010, 7, 28),
36
 
        )
37
 
        a3.comments.create(
38
 
            text="+1",
39
 
            pub_date=datetime(2005, 8, 29),
40
 
        )
41
 
 
42
 
        c = Category.objects.create(name="serious-news")
43
 
        c.articles.add(a1, a3)
44
 
 
45
 
        self.assertQuerysetEqual(
46
 
            Comment.objects.dates("article__pub_date", "year"), [
47
 
                datetime(2005, 1, 1),
48
 
                datetime(2010, 1, 1),
49
 
            ],
50
 
            lambda d: d,
51
 
        )
52
 
        self.assertQuerysetEqual(
53
 
            Comment.objects.dates("article__pub_date", "month"), [
54
 
                datetime(2005, 7, 1),
55
 
                datetime(2010, 7, 1),
56
 
            ],
57
 
            lambda d: d
58
 
        )
59
 
        self.assertQuerysetEqual(
60
 
            Comment.objects.dates("article__pub_date", "day"), [
61
 
                datetime(2005, 7, 28),
62
 
                datetime(2010, 7, 28),
63
 
            ],
64
 
            lambda d: d
65
 
        )
66
 
        self.assertQuerysetEqual(
67
 
            Article.objects.dates("comments__pub_date", "day"), [
68
 
                datetime(2005, 7, 28),
69
 
                datetime(2005, 7, 29),
70
 
                datetime(2005, 8, 29),
71
 
                datetime(2010, 7, 28),
72
 
            ],
73
 
            lambda d: d
74
 
        )
75
 
        self.assertQuerysetEqual(
76
 
            Article.objects.dates("comments__approval_date", "day"), []
77
 
        )
78
 
        self.assertQuerysetEqual(
79
 
            Category.objects.dates("articles__pub_date", "day"), [
80
 
                datetime(2005, 7, 28),
81
 
            ],
82
 
            lambda d: d,
83
 
        )