From 0ced8b0bb211fca38669293b15316930e0d648fd Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 25 Jun 2007 12:47:19 +0000 Subject: 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 --- tests/regressiontests/datatypes/__init__.py | 0 tests/regressiontests/datatypes/models.py | 59 ++++++++++++++++++++++ tests/regressiontests/defaultfilters/tests.py | 20 ++++++-- tests/regressiontests/forms/regressions.py | 2 +- tests/regressiontests/forms/tests.py | 24 +++++++-- tests/regressiontests/serializers_regress/tests.py | 16 ++++++ tests/regressiontests/templates/tests.py | 2 +- tests/regressiontests/templates/urls.py | 2 +- 8 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 tests/regressiontests/datatypes/__init__.py create mode 100644 tests/regressiontests/datatypes/models.py (limited to 'tests') diff --git a/tests/regressiontests/datatypes/__init__.py b/tests/regressiontests/datatypes/__init__.py new file mode 100644 index 0000000000..e69de29bb2 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 + +>>> 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'http://short.com/' >>> urlizetrunc(u'http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20) -u'http://www.google.co...' - ->>> wordcount(u'') +u'http://www.google....' + +>>> urlizetrunc('http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20) +u'http://www.google...' + +# Check truncating of URIs which are the exact length +>>> uri = 'http://31characteruri.com/test/' +>>> len(uri) +31 +>>> urlizetrunc(uri, 31) +u'http://31characteruri.com/test/' +>>> urlizetrunc(uri, 30) +u'http://31characteruri.com/t...' +>>> urlizetrunc(uri, 2) +u'...' + +>>> 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'

\n

' +u'\n

' >>> 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'
    • This field is required.
    • This field is required.
  • >>> print p.as_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.
  • Last name:
  • Birthday:
  • >>> print p.as_p() -

    +

    First name:

    Last name:

    Birthday:

    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, ""), (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, ""), ] +# 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[^/]+)/$', views.client_action), - url(r'^named-client/(\d+)/$', views.client, name="named-client"), + url(r'^named-client/(\d+)/$', views.client, name="named.client"), ) -- cgit v1.2.1