~ubuntu-branches/ubuntu/oneiric/python-django/oneiric

« back to all changes in this revision

Viewing changes to tests/regressiontests/model_regress/models.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2011-02-17 13:34:07 UTC
  • mfrom: (1.1.13 upstream) (4.4.12 sid)
  • Revision ID: james.westby@ubuntu.com-20110217133407-rwr88elhhq6j7ba0
Tags: 1.2.5-1ubuntu1
* Merge from Debian for security fixes (LP: #719031). Remaining changes:
  - debian/control: don't Build-Depends on locales-all, which doesn't exist
    in natty
* Drop the following patches, now included upstream:
  - debian/patches/07_security_admin_infoleak.diff
  - debian/patches/08_security_pasword_reset_dos.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# coding: utf-8
2
 
import datetime
 
2
from django.db import models
3
3
 
4
 
from django.conf import settings
5
 
from django.db import models, DEFAULT_DB_ALIAS
6
 
from django.utils import tzinfo
7
4
 
8
5
CHOICES = (
9
6
    (1, 'first'),
58
55
        # object).
59
56
        return 'Názov: %s' % self.name
60
57
 
61
 
 
62
 
__test__ = {'API_TESTS': """
63
 
(NOTE: Part of the regression test here is merely parsing the model
64
 
declaration. The verbose_name, in particular, did not always work.)
65
 
 
66
 
An empty choice field should return None for the display name.
67
 
 
68
 
>>> from datetime import datetime
69
 
>>> a = Article(headline="Look at me!", pub_date=datetime.now())
70
 
>>> a.save()
71
 
>>> a.get_status_display() is None
72
 
True
73
 
 
74
 
Empty strings should be returned as Unicode
75
 
>>> a2 = Article.objects.get(pk=a.id)
76
 
>>> a2.misc_data
77
 
u''
78
 
 
79
 
# TextFields can hold more than 4000 characters (this was broken in Oracle).
80
 
>>> a3 = Article(headline="Really, really big", pub_date=datetime.now())
81
 
>>> a3.article_text = "ABCDE" * 1000
82
 
>>> a3.save()
83
 
>>> a4 = Article.objects.get(pk=a3.id)
84
 
>>> len(a4.article_text)
85
 
5000
86
 
 
87
 
# Regression test for #659
88
 
>>> import datetime
89
 
>>> p = Party.objects.create(when = datetime.datetime(1999, 12, 31))
90
 
>>> p = Party.objects.create(when = datetime.datetime(1998, 12, 31))
91
 
>>> p = Party.objects.create(when = datetime.datetime(1999, 1, 1))
92
 
>>> [p.when for p in Party.objects.filter(when__month=2)]
93
 
[]
94
 
>>> [p.when for p in Party.objects.filter(when__month=1)]
95
 
[datetime.date(1999, 1, 1)]
96
 
>>> [p.when for p in Party.objects.filter(when__month=12)]
97
 
[datetime.date(1999, 12, 31), datetime.date(1998, 12, 31)]
98
 
>>> [p.when for p in Party.objects.filter(when__year=1998)]
99
 
[datetime.date(1998, 12, 31)]
100
 
 
101
 
# Regression test for #8510
102
 
>>> [p.when for p in Party.objects.filter(when__day='31')]
103
 
[datetime.date(1999, 12, 31), datetime.date(1998, 12, 31)]
104
 
>>> [p.when for p in Party.objects.filter(when__month='12')]
105
 
[datetime.date(1999, 12, 31), datetime.date(1998, 12, 31)]
106
 
>>> [p.when for p in Party.objects.filter(when__year='1998')]
107
 
[datetime.date(1998, 12, 31)]
108
 
 
109
 
# Date filtering was failing with NULL date values in SQLite (regression test
110
 
# for #3501, amongst other things).
111
 
>>> _ = Party.objects.create()
112
 
>>> p = Party.objects.filter(when__month=1)[0]
113
 
>>> p.when
114
 
datetime.date(1999, 1, 1)
115
 
>>> l = Party.objects.filter(pk=p.pk).dates("when", "month")
116
 
>>> l[0].month == 1
117
 
True
118
 
 
119
 
# Check that get_next_by_FIELD and get_previous_by_FIELD don't crash when we
120
 
# have usecs values stored on the database
121
 
#
122
 
# [It crashed after the Field.get_db_prep_* refactor, because on most backends
123
 
#  DateTimeFields supports usecs, but DateTimeField.to_python didn't recognize
124
 
#  them. (Note that Model._get_next_or_previous_by_FIELD coerces values to
125
 
#  strings)]
126
 
#
127
 
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 16, 0, 0))
128
 
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 6, 1, 1))
129
 
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 13, 1, 1))
130
 
>>> e = Event.objects.create(when = datetime.datetime(2000, 1, 1, 12, 0, 20, 24))
131
 
>>> e.get_next_by_when().when
132
 
datetime.datetime(2000, 1, 1, 13, 1, 1)
133
 
>>> e.get_previous_by_when().when
134
 
datetime.datetime(2000, 1, 1, 6, 1, 1)
135
 
 
136
 
# Check Department and Worker
137
 
>>> d = Department(id=10, name='IT')
138
 
>>> d.save()
139
 
>>> w = Worker(department=d, name='Full-time')
140
 
>>> w.save()
141
 
>>> w
142
 
<Worker: Full-time>
143
 
 
144
 
# Models with broken unicode methods should still have a printable repr
145
 
>>> b = BrokenUnicodeMethod(name="Jerry")
146
 
>>> b.save()
147
 
>>> BrokenUnicodeMethod.objects.all()
148
 
[<BrokenUnicodeMethod: [Bad Unicode data]>]
149
 
 
150
 
"""}
151
 
 
152
 
if settings.DATABASES[DEFAULT_DB_ALIAS]['ENGINE'] not in (
153
 
        "django.db.backends.mysql",
154
 
        "django.db.backends.oracle"):
155
 
    __test__["timezone-tests"] = """
156
 
# Saving an updating with timezone-aware datetime Python objects. Regression
157
 
# test for #10443.
158
 
 
159
 
# The idea is that all these creations and saving should work without crashing.
160
 
# It's not rocket science.
161
 
>>> Article.objects.all().delete()
162
 
>>> dt1 = datetime.datetime(2008, 8, 31, 16, 20, tzinfo=tzinfo.FixedOffset(600))
163
 
>>> dt2 = datetime.datetime(2008, 8, 31, 17, 20, tzinfo=tzinfo.FixedOffset(600))
164
 
>>> obj = Article.objects.create(headline="A headline", pub_date=dt1, article_text="foo")
165
 
 
166
 
>>> obj.pub_date = dt2
167
 
>>> obj.save()
168
 
>>> Article.objects.filter(headline="A headline").update(pub_date=dt1)
169
 
1
170
 
 
171
 
"""
 
58
class NonAutoPK(models.Model):
 
59
    name = models.CharField(max_length=10, primary_key=True)