summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 12:47:19 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-06-25 12:47:19 +0000
commit0ced8b0bb211fca38669293b15316930e0d648fd (patch)
treea6f4733859aed03765c396f843770b503c36ec90 /tests
parentf4387422f0a556fb2469500fb9d408306bead02c (diff)
downloaddjango-0ced8b0bb211fca38669293b15316930e0d648fd.tar.gz
unicode: Merged from trunk up to [5530]. Oracle backend has not been ported to
support unicode yet. git-svn-id: http://code.djangoproject.com/svn/django/branches/unicode@5531 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/regressiontests/datatypes/__init__.py0
-rw-r--r--tests/regressiontests/datatypes/models.py59
-rw-r--r--tests/regressiontests/defaultfilters/tests.py20
-rw-r--r--tests/regressiontests/forms/regressions.py2
-rw-r--r--tests/regressiontests/forms/tests.py24
-rw-r--r--tests/regressiontests/serializers_regress/tests.py16
-rw-r--r--tests/regressiontests/templates/tests.py2
-rw-r--r--tests/regressiontests/templates/urls.py2
8 files changed, 115 insertions, 10 deletions
diff --git a/tests/regressiontests/datatypes/__init__.py b/tests/regressiontests/datatypes/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/tests/regressiontests/datatypes/__init__.py
diff --git a/tests/regressiontests/datatypes/models.py b/tests/regressiontests/datatypes/models.py
new file mode 100644
index 0000000000..8c5c8c285d
--- /dev/null
+++ b/tests/regressiontests/datatypes/models.py
@@ -0,0 +1,59 @@
+"""
+This is a basic model to test saving and loading boolean and date-related
+types, which in the past were problematic for some database backends.
+"""
+
+from django.db import models
+from django.conf import settings
+
+class Donut(models.Model):
+ name = models.CharField(maxlength=100)
+ is_frosted = models.BooleanField(default=False)
+ has_sprinkles = models.NullBooleanField()
+ baked_date = models.DateField(null=True)
+ baked_time = models.TimeField(null=True)
+ consumed_at = models.DateTimeField(null=True)
+
+ class Meta:
+ ordering = ('consumed_at',)
+
+ def __str__(self):
+ return self.name
+
+__test__ = {'API_TESTS': """
+# No donuts are in the system yet.
+>>> Donut.objects.all()
+[]
+
+>>> d = Donut(name='Apple Fritter')
+
+# Ensure we're getting True and False, not 0 and 1
+>>> d.is_frosted
+False
+>>> d.has_sprinkles
+>>> d.has_sprinkles = True
+>>> d.has_sprinkles == True
+True
+>>> d.save()
+>>> d2 = Donut.objects.all()[0]
+>>> d2
+<Donut: Apple Fritter>
+>>> d2.is_frosted == False
+True
+>>> d2.has_sprinkles == True
+True
+
+>>> import datetime
+>>> d2.baked_date = datetime.date(year=1938, month=6, day=4)
+>>> d2.baked_time = datetime.time(hour=5, minute=30)
+>>> d2.consumed_at = datetime.datetime(year=2007, month=4, day=20, hour=16, minute=19, second=59)
+>>> d2.save()
+
+>>> d3 = Donut.objects.all()[0]
+>>> d3.baked_date
+datetime.date(1938, 6, 4)
+>>> d3.baked_time
+datetime.time(5, 30)
+>>> d3.consumed_at
+datetime.datetime(2007, 4, 20, 16, 19, 59)
+"""}
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 1acad6135c..53a92edaed 100644
--- a/tests/regressiontests/defaultfilters/tests.py
+++ b/tests/regressiontests/defaultfilters/tests.py
@@ -124,9 +124,23 @@ u'fran%C3%A7ois%20%26%20jill'
u'<a href="http://short.com/" rel="nofollow">http://short.com/</a>'
>>> urlizetrunc(u'http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20)
-u'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google.co...</a>'
-
->>> wordcount(u'')
+u'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google....</a>'
+
+>>> urlizetrunc('http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20)
+u'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google...</a>'
+
+# Check truncating of URIs which are the exact length
+>>> uri = 'http://31characteruri.com/test/'
+>>> len(uri)
+31
+>>> urlizetrunc(uri, 31)
+u'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/test/</a>'
+>>> urlizetrunc(uri, 30)
+u'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/t...</a>'
+>>> urlizetrunc(uri, 2)
+u'<a href="http://31characteruri.com/test/" rel="nofollow">...</a>'
+
+>>> wordcount('')
0
>>> wordcount(u'oneword')
diff --git a/tests/regressiontests/forms/regressions.py b/tests/regressiontests/forms/regressions.py
index 54b9138b20..df2ef578a1 100644
--- a/tests/regressiontests/forms/regressions.py
+++ b/tests/regressiontests/forms/regressions.py
@@ -57,7 +57,7 @@ Translated error messages used to be buggy.
>>> activate('ru')
>>> f = SomeForm({})
>>> f.as_p()
-u'<p><ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul></p>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
+u'<ul class="errorlist"><li>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0435 \u043f\u043e\u043b\u0435.</li></ul>\n<p><label for="id_somechoice_0">\xc5\xf8\xdf:</label> <ul>\n<li><label><input type="radio" id="id_somechoice_0" value="\xc5" name="somechoice" /> En tied\xe4</label></li>\n<li><label><input type="radio" id="id_somechoice_1" value="\xf8" name="somechoice" /> Mies</label></li>\n<li><label><input type="radio" id="id_somechoice_2" value="\xdf" name="somechoice" /> Nainen</label></li>\n</ul></p>'
>>> deactivate()
#######################
diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py
index a2e23b8b42..67d527a08e 100644
--- a/tests/regressiontests/forms/tests.py
+++ b/tests/regressiontests/forms/tests.py
@@ -1859,8 +1859,12 @@ ValidationError: [u'Enter a valid date.']
>>> f = SplitDateTimeField(required=False)
>>> f.clean([datetime.date(2006, 1, 10), datetime.time(7, 30)])
datetime.datetime(2006, 1, 10, 7, 30)
+>>> f.clean(['2006-01-10', '07:30'])
+datetime.datetime(2006, 1, 10, 7, 30)
>>> f.clean(None)
>>> f.clean('')
+>>> f.clean([''])
+>>> f.clean(['', ''])
>>> f.clean('hello')
Traceback (most recent call last):
...
@@ -1877,6 +1881,18 @@ ValidationError: [u'Enter a valid time.']
Traceback (most recent call last):
...
ValidationError: [u'Enter a valid date.']
+>>> f.clean(['2006-01-10', ''])
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid time.']
+>>> f.clean(['2006-01-10'])
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid time.']
+>>> f.clean(['', '07:30'])
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a valid date.']
#########
# Forms #
@@ -1958,11 +1974,11 @@ AttributeError: 'Person' object has no attribute 'cleaned_data'
<li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></li>
<li><ul class="errorlist"><li>This field is required.</li></ul><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></li>
>>> print p.as_p()
-<p><ul class="errorlist"><li>This field is required.</li></ul></p>
+<ul class="errorlist"><li>This field is required.</li></ul>
<p><label for="id_first_name">First name:</label> <input type="text" name="first_name" id="id_first_name" /></p>
-<p><ul class="errorlist"><li>This field is required.</li></ul></p>
+<ul class="errorlist"><li>This field is required.</li></ul>
<p><label for="id_last_name">Last name:</label> <input type="text" name="last_name" id="id_last_name" /></p>
-<p><ul class="errorlist"><li>This field is required.</li></ul></p>
+<ul class="errorlist"><li>This field is required.</li></ul>
<p><label for="id_birthday">Birthday:</label> <input type="text" name="birthday" id="id_birthday" /></p>
If you don't pass any values to the Form's __init__(), or if you pass None,
@@ -2668,7 +2684,7 @@ its field's order in the form.
<li>Last name: <input type="text" name="last_name" value="Lennon" /></li>
<li>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></li>
>>> print p.as_p()
-<p><ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul></p>
+<ul class="errorlist"><li>(Hidden field hidden_text) This field is required.</li></ul>
<p>First name: <input type="text" name="first_name" value="John" /></p>
<p>Last name: <input type="text" name="last_name" value="Lennon" /></p>
<p>Birthday: <input type="text" name="birthday" value="1940-10-9" /><input type="hidden" name="hidden_text" /></p>
diff --git a/tests/regressiontests/serializers_regress/tests.py b/tests/regressiontests/serializers_regress/tests.py
index 4afd87ccc8..7c6da9d356 100644
--- a/tests/regressiontests/serializers_regress/tests.py
+++ b/tests/regressiontests/serializers_regress/tests.py
@@ -15,6 +15,7 @@ from django.utils.functional import curry
from django.core import serializers
from django.db import transaction
from django.core import management
+from django.conf import settings
from models import *
try:
@@ -119,10 +120,13 @@ test_data = [
(data_obj, 31, DateTimeData, None),
(data_obj, 40, EmailData, "hovercraft@example.com"),
(data_obj, 41, EmailData, None),
+ (data_obj, 42, EmailData, ""),
(data_obj, 50, FileData, 'file:///foo/bar/whiz.txt'),
(data_obj, 51, FileData, None),
+ (data_obj, 52, FileData, ""),
(data_obj, 60, FilePathData, "/foo/bar/whiz.txt"),
(data_obj, 61, FilePathData, None),
+ (data_obj, 62, FilePathData, ""),
(data_obj, 70, DecimalData, decimal.Decimal('12.345')),
(data_obj, 71, DecimalData, decimal.Decimal('-12.345')),
(data_obj, 72, DecimalData, decimal.Decimal('0.0')),
@@ -149,6 +153,7 @@ test_data = [
(data_obj, 131, PositiveSmallIntegerData, None),
(data_obj, 140, SlugData, "this-is-a-slug"),
(data_obj, 141, SlugData, None),
+ (data_obj, 142, SlugData, ""),
(data_obj, 150, SmallData, 12),
(data_obj, 151, SmallData, -12),
(data_obj, 152, SmallData, 0),
@@ -163,8 +168,10 @@ The end."""),
(data_obj, 171, TimeData, None),
(data_obj, 180, USStateData, "MA"),
(data_obj, 181, USStateData, None),
+ (data_obj, 182, USStateData, ""),
(data_obj, 190, XMLData, "<foo></foo>"),
(data_obj, 191, XMLData, None),
+ (data_obj, 192, XMLData, ""),
(generic_obj, 200, GenericData, ['Generic Object 1', 'tag1', 'tag2']),
(generic_obj, 201, GenericData, ['Generic Object 2', 'tag2', 'tag3']),
@@ -244,6 +251,15 @@ The end."""),
# (pk_obj, 790, XMLPKData, "<foo></foo>"),
]
+# Because Oracle treats the empty string as NULL, Oracle is expected to fail
+# when field.empty_strings_allowed is True and the value is None; skip these
+# tests.
+if settings.DATABASE_ENGINE == 'oracle':
+ test_data = [data for data in test_data
+ if not (data[0] == data_obj and
+ data[2]._meta.get_field('data').empty_strings_allowed and
+ data[3] is None)]
+
# Dynamically create serializer tests to ensure that all
# registered serializers are automatically tested.
class SerializerTests(unittest.TestCase):
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index b6615e1aa9..c78ccff678 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -731,7 +731,7 @@ class Templates(unittest.TestCase):
'url01' : ('{% url regressiontests.templates.views.client client.id %}', {'client': {'id': 1}}, '/url_tag/client/1/'),
'url02' : ('{% url regressiontests.templates.views.client_action client.id, action="update" %}', {'client': {'id': 1}}, '/url_tag/client/1/update/'),
'url03' : ('{% url regressiontests.templates.views.index %}', {}, '/url_tag/'),
- 'url04' : ('{% url named-client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
+ 'url04' : ('{% url named.client client.id %}', {'client': {'id': 1}}, '/url_tag/named-client/1/'),
# Failures
'url-fail01' : ('{% url %}', {}, template.TemplateSyntaxError),
diff --git a/tests/regressiontests/templates/urls.py b/tests/regressiontests/templates/urls.py
index eaa9fd5d9f..5fbade5c58 100644
--- a/tests/regressiontests/templates/urls.py
+++ b/tests/regressiontests/templates/urls.py
@@ -7,5 +7,5 @@ urlpatterns = patterns('',
(r'^$', views.index),
(r'^client/(\d+)/$', views.client),
(r'^client/(\d+)/(?P<action>[^/]+)/$', views.client_action),
- url(r'^named-client/(\d+)/$', views.client, name="named-client"),
+ url(r'^named-client/(\d+)/$', views.client, name="named.client"),
)