summaryrefslogtreecommitdiff
path: root/tests/regressiontests
diff options
context:
space:
mode:
authorMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-29 20:38:41 +0000
committerMalcolm Tredinnick <malcolm.tredinnick@gmail.com>2007-11-29 20:38:41 +0000
commitdfe05d94b853073e2762250e1b4cd64ce9ef1df0 (patch)
tree4e6aea30920e85556903dd67ca329fe69e9f2a7d /tests/regressiontests
parentb43a0180322b42925c4c27b5ccdf2e876309c53b (diff)
queryset-refactor: Merged from trunk up to [6752].
git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@6753 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
-rw-r--r--tests/regressiontests/dateformat/tests.py4
-rw-r--r--tests/regressiontests/defaultfilters/tests.py2
-rw-r--r--tests/regressiontests/forms/fields.py14
-rw-r--r--tests/regressiontests/forms/localflavor/ca.py4
-rw-r--r--tests/regressiontests/forms/widgets.py7
-rw-r--r--tests/regressiontests/templates/filters.py16
-rw-r--r--tests/regressiontests/templates/tests.py7
-rw-r--r--tests/regressiontests/utils/datastructures.py51
-rw-r--r--tests/regressiontests/utils/tests.py13
-rw-r--r--tests/regressiontests/utils/timesince.py2
-rw-r--r--tests/regressiontests/views/tests/static.py10
11 files changed, 122 insertions, 8 deletions
diff --git a/tests/regressiontests/dateformat/tests.py b/tests/regressiontests/dateformat/tests.py
index 30c9a4e6dd..481e36a7dd 100644
--- a/tests/regressiontests/dateformat/tests.py
+++ b/tests/regressiontests/dateformat/tests.py
@@ -66,6 +66,9 @@ u'1979 189 CET'
>>> format(my_birthday, r'jS o\f F')
u'8th of July'
+
+>>> format(the_future, r'Y')
+u'2100'
"""
from django.utils import dateformat, translation
@@ -84,3 +87,4 @@ except AttributeError:
my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
summertime = datetime.datetime(2005, 10, 30, 1, 00)
wintertime = datetime.datetime(2005, 10, 30, 4, 00)
+the_future = datetime.datetime(2100, 10, 25, 0, 00)
diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
index 26d448900d..bfa03cd6e1 100644
--- a/tests/regressiontests/defaultfilters/tests.py
+++ b/tests/regressiontests/defaultfilters/tests.py
@@ -37,6 +37,8 @@ u''
u'13.1031'
>>> floatformat(u'foo', u'bar')
u''
+>>> floatformat(None)
+u''
>>> addslashes(u'"double quotes" and \'single quotes\'')
u'\\"double quotes\\" and \\\'single quotes\\\''
diff --git a/tests/regressiontests/forms/fields.py b/tests/regressiontests/forms/fields.py
index 3b93d70338..cff5db6fca 100644
--- a/tests/regressiontests/forms/fields.py
+++ b/tests/regressiontests/forms/fields.py
@@ -323,6 +323,10 @@ Decimal("3.14")
Traceback (most recent call last):
...
ValidationError: [u'Enter a number.']
+>>> f.clean(u'łąść')
+Traceback (most recent call last):
+...
+ValidationError: [u'Enter a number.']
>>> f.clean('1.0 ')
Decimal("1.0")
>>> f.clean(' 1.0')
@@ -914,6 +918,11 @@ False
>>> f.clean('Django rocks')
True
+>>> f.clean('True')
+True
+>>> f.clean('False')
+False
+
>>> f = BooleanField(required=False)
>>> f.clean('')
False
@@ -930,6 +939,11 @@ False
>>> f.clean('Django rocks')
True
+A form's BooleanField with a hidden widget will output the string 'False', so
+that should clean to the boolean value False:
+>>> f.clean('False')
+False
+
# ChoiceField #################################################################
>>> f = ChoiceField(choices=[('1', '1'), ('2', '2')])
diff --git a/tests/regressiontests/forms/localflavor/ca.py b/tests/regressiontests/forms/localflavor/ca.py
index baeb2ad9a8..a13a6de65f 100644
--- a/tests/regressiontests/forms/localflavor/ca.py
+++ b/tests/regressiontests/forms/localflavor/ca.py
@@ -147,6 +147,10 @@ u'BC'
u'NS'
>>> f.clean(' manitoba ')
u'MB'
+>>> f.clean(' new brunswick ')
+u'NB'
+>>> f.clean('NB')
+u'NB'
>>> f.clean('T2S 2H7')
Traceback (most recent call last):
...
diff --git a/tests/regressiontests/forms/widgets.py b/tests/regressiontests/forms/widgets.py
index ea8cf135aa..0e69602103 100644
--- a/tests/regressiontests/forms/widgets.py
+++ b/tests/regressiontests/forms/widgets.py
@@ -129,6 +129,13 @@ u'<input type="hidden" class="fun" value="\u0160\u0110\u0106\u017d\u0107\u017e\u
>>> w.render('email', '', attrs={'class': 'special'})
u'<input type="hidden" class="special" name="email" />'
+Boolean values are rendered to their string forms ("True" and "False").
+>>> w = HiddenInput()
+>>> w.render('get_spam', False)
+u'<input type="hidden" name="get_spam" value="False" />'
+>>> w.render('get_spam', True)
+u'<input type="hidden" name="get_spam" value="True" />'
+
# MultipleHiddenInput Widget ##################################################
>>> w = MultipleHiddenInput()
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
index 2a06703948..4175bdbe5f 100644
--- a/tests/regressiontests/templates/filters.py
+++ b/tests/regressiontests/templates/filters.py
@@ -12,6 +12,15 @@ from datetime import datetime, timedelta
from django.utils.tzinfo import LocalTimezone
from django.utils.safestring import mark_safe
+# These two classes are used to test auto-escaping of __unicode__ output.
+class UnsafeClass:
+ def __unicode__(self):
+ return u'you & me'
+
+class SafeClass:
+ def __unicode__(self):
+ return mark_safe(u'you &gt; me')
+
# RESULT SYNTAX --
# 'template_name': ('template contents', 'context dict',
# 'expected string output' or Exception class)
@@ -227,4 +236,11 @@ def get_filter_tests():
'chaining12': ('{% autoescape off %}{{ a|cut:"b"|safe }}{% endautoescape %}', {"a": "a < b"}, "a < "),
'chaining13': ('{{ a|safe|force_escape }}', {"a": "a < b"}, "a &lt; b"),
'chaining14': ('{% autoescape off %}{{ a|safe|force_escape }}{% endautoescape %}', {"a": "a < b"}, "a &lt; b"),
+
+ # Filters decorated with stringfilter still respect is_safe.
+ 'autoescape-stringfilter01': (r'{{ unsafe|capfirst }}', {'unsafe': UnsafeClass()}, 'You &amp; me'),
+ 'autoescape-stringfilter02': (r'{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}', {'unsafe': UnsafeClass()}, 'You & me'),
+ 'autoescape-stringfilter03': (r'{{ safe|capfirst }}', {'safe': SafeClass()}, 'You &gt; me'),
+ 'autoescape-stringfilter04': (r'{% autoescape off %}{{ safe|capfirst }}{% endautoescape %}', {'safe': SafeClass()}, 'You &gt; me'),
}
+
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index f3c131dd91..cbbd88b06c 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -899,7 +899,12 @@ class Templates(unittest.TestCase):
# Literal string arguments to filters, if used in the result, are
# safe.
- 'basic-syntax08': (r'{% autoescape on %}{{ var|default_if_none:" endquote\" hah" }}{% endautoescape %}', {"var": None}, ' endquote" hah'),
+ 'autoescape-tag08': (r'{% autoescape on %}{{ var|default_if_none:" endquote\" hah" }}{% endautoescape %}', {"var": None}, ' endquote" hah'),
+
+ # Objects which return safe strings as their __unicode__ method
+ # won't get double-escaped.
+ 'autoescape-tag09': (r'{{ unsafe }}', {'unsafe': filters.UnsafeClass()}, 'you &amp; me'),
+ 'autoescape-tag10': (r'{{ safe }}', {'safe': filters.SafeClass()}, 'you &gt; me'),
# The "safe" and "escape" filters cannot work due to internal
# implementation details (fortunately, the (no)autoescape block
diff --git a/tests/regressiontests/utils/datastructures.py b/tests/regressiontests/utils/datastructures.py
new file mode 100644
index 0000000000..52bf81a9e0
--- /dev/null
+++ b/tests/regressiontests/utils/datastructures.py
@@ -0,0 +1,51 @@
+"""
+>>> from django.utils.datastructures import SortedDict
+
+>>> d = SortedDict()
+>>> d[7] = 'seven'
+>>> d[1] = 'one'
+>>> d[9] = 'nine'
+>>> d.keys()
+[7, 1, 9]
+>>> d.values()
+['seven', 'one', 'nine']
+>>> d.items()
+[(7, 'seven'), (1, 'one'), (9, 'nine')]
+
+# Overwriting an item keeps it's place.
+>>> d[1] = 'ONE'
+>>> d.values()
+['seven', 'ONE', 'nine']
+
+# New items go to the end.
+>>> d[0] = 'nil'
+>>> d.keys()
+[7, 1, 9, 0]
+
+# Deleting an item, then inserting the same key again will place it at the end.
+>>> del d[7]
+>>> d.keys()
+[1, 9, 0]
+>>> d[7] = 'lucky number 7'
+>>> d.keys()
+[1, 9, 0, 7]
+
+# Changing the keys won't do anything, it's only a copy of the keys dict.
+>>> k = d.keys()
+>>> k.remove(9)
+>>> d.keys()
+[1, 9, 0, 7]
+
+# Initialising a SortedDict with two keys will just take the first one. A real
+# dict will actually take the second value so we will too, but we'll keep the
+# ordering from the first key found.
+>>> tuples = ((2, 'two'), (1, 'one'), (2, 'second-two'))
+>>> d = SortedDict(tuples)
+>>> d.keys()
+[2, 1]
+>>> real_dict = dict(tuples)
+>>> real_dict.values()
+['one', 'second-two']
+>>> d.values()
+['second-two', 'one']
+""" \ No newline at end of file
diff --git a/tests/regressiontests/utils/tests.py b/tests/regressiontests/utils/tests.py
index eb3a722888..abcd7212d8 100644
--- a/tests/regressiontests/utils/tests.py
+++ b/tests/regressiontests/utils/tests.py
@@ -6,7 +6,14 @@ from unittest import TestCase
from django.utils import html, checksums
-from timesince import timesince_tests
+import timesince
+import datastructures
+
+# Extra tests
+__test__ = {
+ 'timesince': timesince,
+ 'datastructures': datastructures,
+}
class TestUtilsHtml(TestCase):
@@ -142,10 +149,6 @@ class TestUtilsChecksums(TestCase):
for value, output in items:
self.check_output(f, value, output)
-__test__ = {
- 'timesince_tests': timesince_tests,
-}
-
if __name__ == "__main__":
import doctest
doctest.testmod()
diff --git a/tests/regressiontests/utils/timesince.py b/tests/regressiontests/utils/timesince.py
index 30200be6e9..4f304ec7f7 100644
--- a/tests/regressiontests/utils/timesince.py
+++ b/tests/regressiontests/utils/timesince.py
@@ -1,4 +1,4 @@
-timesince_tests = """
+"""
>>> from datetime import datetime, timedelta
>>> from django.utils.timesince import timesince
diff --git a/tests/regressiontests/views/tests/static.py b/tests/regressiontests/views/tests/static.py
index 0a67cf543e..c731b249e8 100644
--- a/tests/regressiontests/views/tests/static.py
+++ b/tests/regressiontests/views/tests/static.py
@@ -12,4 +12,12 @@ class StaticTests(TestCase):
for filename in media_files:
response = self.client.get('/views/site_media/%s' % filename)
file = open(path.join(media_dir, filename))
- self.assertEquals(file.read(), response.content) \ No newline at end of file
+ self.assertEquals(file.read(), response.content)
+
+ def test_copes_with_empty_path_component(self):
+ file_name = 'file.txt'
+ response = self.client.get('/views/site_media//%s' % file_name)
+ file = open(path.join(media_dir, file_name))
+ self.assertEquals(file.read(), response.content)
+
+