diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/regressiontests/datatypes/__init__.py | 0 | ||||
| -rw-r--r-- | tests/regressiontests/datatypes/models.py | 59 | ||||
| -rw-r--r-- | tests/regressiontests/defaultfilters/tests.py | 13 | ||||
| -rw-r--r-- | tests/regressiontests/forms/tests.py | 24 | ||||
| -rw-r--r-- | tests/regressiontests/serializers_regress/tests.py | 16 | ||||
| -rw-r--r-- | tests/regressiontests/templates/tests.py | 2 | ||||
| -rw-r--r-- | tests/regressiontests/templates/urls.py | 2 |
7 files changed, 109 insertions, 7 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 4a2e9432b0..b35636aba6 100644 --- a/tests/regressiontests/defaultfilters/tests.py +++ b/tests/regressiontests/defaultfilters/tests.py @@ -121,7 +121,18 @@ u'\xcb' '<a href="http://short.com/" rel="nofollow">http://short.com/</a>' >>> urlizetrunc('http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=', 20) -'<a href="http://www.google.co.uk/search?hl=en&q=some+long+url&btnG=Search&meta=" rel="nofollow">http://www.google.co...</a>' +'<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) +'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/test/</a>' +>>> urlizetrunc(uri, 30) +'<a href="http://31characteruri.com/test/" rel="nofollow">http://31characteruri.com/t...</a>' +>>> urlizetrunc(uri, 2) +'<a href="http://31characteruri.com/test/" rel="nofollow">...</a>' >>> wordcount('') 0 diff --git a/tests/regressiontests/forms/tests.py b/tests/regressiontests/forms/tests.py index 4844267b43..0808ebe97e 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 1a144c8356..febcfa822e 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: @@ -116,10 +117,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')), @@ -146,6 +150,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), @@ -160,8 +165,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']), @@ -241,6 +248,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 e983a539ae..8c2389b28a 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -725,7 +725,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"), ) |
