~ubuntu-branches/ubuntu/quantal/python-django/quantal

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Scott James Remnant
  • Date: 2008-11-15 19:15:33 UTC
  • mfrom: (1.1.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20081115191533-xbt1ut2xf4fvwtvc
Tags: 1.0.1-0ubuntu1
* New upstream release:
  - Bug fixes.

* The tests/ sub-directory appaers to have been dropped upstream, so pull
  our patch to workaround the tests and modify the rules.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
>>> from django.db.models.fields import *
3
 
>>> try:
4
 
...     from decimal import Decimal
5
 
... except ImportError:
6
 
...     from django.utils._decimal import Decimal
7
 
 
8
 
# DecimalField
9
 
 
10
 
>>> f = DecimalField(max_digits=4, decimal_places=2)
11
 
 
12
 
>>> f.to_python(3) == Decimal("3")
13
 
True
14
 
 
15
 
>>> f.to_python("3.14") == Decimal("3.14")
16
 
True
17
 
 
18
 
>>> f.to_python("abc")
19
 
Traceback (most recent call last):
20
 
...
21
 
ValidationError: This value must be a decimal number.
22
 
 
23
 
>>> f = DecimalField(max_digits=5, decimal_places=1)
24
 
>>> x = f.to_python(2)
25
 
>>> y = f.to_python('2.6')
26
 
 
27
 
>>> f._format(x)
28
 
u'2.0'
29
 
>>> f._format(y)
30
 
u'2.6'
31
 
>>> f._format(None)
32
 
>>> f.get_db_prep_lookup('exact', None)
33
 
[None]
34
 
 
35
 
# DateTimeField and TimeField to_python should support usecs:
36
 
>>> f = DateTimeField()
37
 
>>> f.to_python('2001-01-02 03:04:05.000006')
38
 
datetime.datetime(2001, 1, 2, 3, 4, 5, 6)
39
 
>>> f.to_python('2001-01-02 03:04:05.999999')
40
 
datetime.datetime(2001, 1, 2, 3, 4, 5, 999999)
41
 
 
42
 
>>> f = TimeField()
43
 
>>> f.to_python('01:02:03.000004')
44
 
datetime.time(1, 2, 3, 4)
45
 
>>> f.to_python('01:02:03.999999')
46
 
datetime.time(1, 2, 3, 999999)
47
 
 
48
 
# Boolean and null boolean fields
49
 
>>> f = BooleanField()
50
 
>>> for val in (True, '1', 1):
51
 
...     f.get_db_prep_lookup('exact', val)
52
 
[True]
53
 
[True]
54
 
[True]
55
 
>>> for val in (False, '0', 0):
56
 
...     f.get_db_prep_lookup('exact', val)
57
 
[False]
58
 
[False]
59
 
[False]
60
 
 
61
 
>>> f = NullBooleanField()
62
 
>>> for val in (True, '1', 1):
63
 
...     f.get_db_prep_lookup('exact', val)
64
 
[True]
65
 
[True]
66
 
[True]
67
 
>>> for val in (False, '0', 0):
68
 
...     f.get_db_prep_lookup('exact', val)
69
 
[False]
70
 
[False]
71
 
[False]
72
 
>>> f.get_db_prep_lookup('exact', None)
73
 
[None]
74
 
 
75
 
"""