summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJustin Bronn <jbronn@gmail.com>2008-02-08 20:57:56 +0000
committerJustin Bronn <jbronn@gmail.com>2008-02-08 20:57:56 +0000
commitd06e33a54d93c35584c348b286b6fea4ffdd3868 (patch)
tree0cfb5088ec0d9c12df3afce8b85c5c48730e961f /tests
parent40e0a964ea0eab8353a338d5527988f09a0d6e51 (diff)
gis: Merged revisions 7044-7102 via svnmerge from trunk.
git-svn-id: http://code.djangoproject.com/svn/django/branches/gis@7103 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests')
-rw-r--r--tests/modeltests/signals/models.py35
-rw-r--r--tests/regressiontests/datastructures/tests.py13
-rw-r--r--tests/regressiontests/i18n/misc.py45
-rw-r--r--tests/regressiontests/templates/filters.py14
-rw-r--r--tests/regressiontests/templates/tests.py2
5 files changed, 101 insertions, 8 deletions
diff --git a/tests/modeltests/signals/models.py b/tests/modeltests/signals/models.py
index 1fb73828bb..5b0f5f2285 100644
--- a/tests/modeltests/signals/models.py
+++ b/tests/modeltests/signals/models.py
@@ -13,8 +13,16 @@ class Person(models.Model):
return u"%s %s" % (self.first_name, self.last_name)
+def pre_save_nokwargs_test(sender, instance):
+ print 'pre_save_nokwargs signal'
+
+def post_save_nokwargs_test(sender, instance):
+ print 'post_save_nokwargs signal'
+
def pre_save_test(sender, instance, **kwargs):
print 'pre_save signal,', instance
+ if kwargs.get('raw'):
+ print 'Is raw'
def post_save_test(sender, instance, **kwargs):
print 'post_save signal,', instance
@@ -23,16 +31,20 @@ def post_save_test(sender, instance, **kwargs):
print 'Is created'
else:
print 'Is updated'
+ if kwargs.get('raw'):
+ print 'Is raw'
def pre_delete_test(sender, instance, **kwargs):
print 'pre_delete signal,', instance
- print 'instance.id is not None: %s' % (instance.id != None)
+ print 'instance.id is not None: %s' % (instance.id != None)
def post_delete_test(sender, instance, **kwargs):
print 'post_delete signal,', instance
- print 'instance.id is None: %s' % (instance.id == None)
+ print 'instance.id is None: %s' % (instance.id == None)
__test__ = {'API_TESTS':"""
+>>> dispatcher.connect(pre_save_nokwargs_test, signal=models.signals.pre_save)
+>>> dispatcher.connect(post_save_nokwargs_test, signal=models.signals.post_save)
>>> dispatcher.connect(pre_save_test, signal=models.signals.pre_save)
>>> dispatcher.connect(post_save_test, signal=models.signals.post_save)
>>> dispatcher.connect(pre_delete_test, signal=models.signals.pre_delete)
@@ -40,15 +52,28 @@ __test__ = {'API_TESTS':"""
>>> p1 = Person(first_name='John', last_name='Smith')
>>> p1.save()
+pre_save_nokwargs signal
pre_save signal, John Smith
+post_save_nokwargs signal
post_save signal, John Smith
Is created
>>> p1.first_name = 'Tom'
>>> p1.save()
+pre_save_nokwargs signal
+pre_save signal, Tom Smith
+post_save_nokwargs signal
+post_save signal, Tom Smith
+Is updated
+
+>>> p1.save(raw=True)
+pre_save_nokwargs signal
pre_save signal, Tom Smith
+Is raw
+post_save_nokwargs signal
post_save signal, Tom Smith
Is updated
+Is raw
>>> p1.delete()
pre_delete signal, Tom Smith
@@ -59,13 +84,17 @@ instance.id is None: False
>>> p2 = Person(first_name='James', last_name='Jones')
>>> p2.id = 99999
>>> p2.save()
+pre_save_nokwargs signal
pre_save signal, James Jones
+post_save_nokwargs signal
post_save signal, James Jones
Is created
>>> p2.id = 99998
>>> p2.save()
+pre_save_nokwargs signal
pre_save signal, James Jones
+post_save_nokwargs signal
post_save signal, James Jones
Is created
@@ -78,6 +107,8 @@ instance.id is None: False
>>> Person.objects.all()
[<Person: James Jones>]
+>>> dispatcher.disconnect(pre_save_nokwargs_test, signal=models.signals.pre_save)
+>>> dispatcher.disconnect(post_save_nokwargs_test, signal=models.signals.post_save)
>>> dispatcher.disconnect(post_delete_test, signal=models.signals.post_delete)
>>> dispatcher.disconnect(pre_delete_test, signal=models.signals.pre_delete)
>>> dispatcher.disconnect(post_save_test, signal=models.signals.post_save)
diff --git a/tests/regressiontests/datastructures/tests.py b/tests/regressiontests/datastructures/tests.py
index 3b0ccde257..b5dc5d171b 100644
--- a/tests/regressiontests/datastructures/tests.py
+++ b/tests/regressiontests/datastructures/tests.py
@@ -20,6 +20,19 @@
>>> md2['chris']
'cool'
+MergeDict can merge MultiValueDicts
+>>> multi1 = MultiValueDict({'key1': ['value1'], 'key2': ['value2', 'value3']})
+>>> multi2 = MultiValueDict({'key2': ['value4'], 'key4': ['value5', 'value6']})
+>>> mm = MergeDict(multi1, multi2)
+
+# Although 'key2' appears in both dictionaries, only the first value is used.
+>>> mm.getlist('key2')
+['value2', 'value3']
+>>> mm.getlist('key4')
+['value5', 'value6']
+>>> mm.getlist('undefined')
+[]
+
### MultiValueDict ##########################################################
>>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']})
diff --git a/tests/regressiontests/i18n/misc.py b/tests/regressiontests/i18n/misc.py
index fa22fd05d3..eb64263799 100644
--- a/tests/regressiontests/i18n/misc.py
+++ b/tests/regressiontests/i18n/misc.py
@@ -2,6 +2,11 @@ tests = """
>>> from django.utils.translation.trans_real import parse_accept_lang_header
>>> p = parse_accept_lang_header
+#
+# Testing HTTP header parsing. First, we test that we can parse the values
+# according to the spec (and that we extract all the pieces in the right order).
+#
+
Good headers.
>>> p('de')
[('de', 1.0)]
@@ -54,4 +59,44 @@ Bad headers; should always return [].
>>> p('')
[]
+#
+# Now test that we parse a literal HTTP header correctly.
+#
+
+>>> from django.utils.translation.trans_real import get_language_from_request
+>>> g = get_language_from_request
+>>> from django.http import HttpRequest
+>>> r = HttpRequest
+>>> r.COOKIES = {}
+
+These tests assumes the es, es_AR, pt and pt_BR translations exit in the Django
+source tree.
+>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt-br'}
+>>> g(r)
+'pt-br'
+>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'pt'}
+>>> g(r)
+'pt'
+>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es,de'}
+>>> g(r)
+'es'
+>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-ar,de'}
+>>> g(r)
+'es-ar'
+
+This test assumes there won't be a Django translation to a US variation
+of the Spanish language, a safe assumption. When the user sets it
+as the preferred language, the main 'es' translation should be selected
+instead.
+>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'es-us'}
+>>> g(r)
+'es'
+
+This tests the following scenario: there isn't a main language (zh)
+translation of Django but there is a translation to variation (zh_CN)
+the user sets zh-cn as the preferred language, it should be selected by
+Django without falling back nor ignoring it.
+>>> r.META = {'HTTP_ACCEPT_LANGUAGE': 'zh-cn,de'}
+>>> g(r)
+'zh-cn'
"""
diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py
index fd73dc57ba..c780a64baf 100644
--- a/tests/regressiontests/templates/filters.py
+++ b/tests/regressiontests/templates/filters.py
@@ -98,8 +98,8 @@ def get_filter_tests():
'filter-upper01': ('{% autoescape off %}{{ a|upper }} {{ b|upper }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, u"A & B A &AMP; B"),
'filter-upper02': ('{{ a|upper }} {{ b|upper }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, u"A &amp; B A &amp;AMP; B"),
- 'filter-urlize01': ('{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http://example.com/x=&y=</a> <a href="http://example.com?x=&y=" rel="nofollow">http://example.com?x=&y=</a>'),
- 'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'<a href="http://example.com/x=&y=" rel="nofollow">http://example.com/x=&amp;y=</a> <a href="http://example.com?x=&y=" rel="nofollow">http://example.com?x=&y=</a>'),
+ 'filter-urlize01': ('{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&amp;y=")}, u'<a href="http://example.com/?x=&y=" rel="nofollow">http://example.com/?x=&y=</a> <a href="http://example.com?x=&amp;y=" rel="nofollow">http://example.com?x=&amp;y=</a>'),
+ 'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&amp;y=")}, u'<a href="http://example.com/?x=&amp;y=" rel="nofollow">http://example.com/?x=&amp;y=</a> <a href="http://example.com?x=&amp;y=" rel="nofollow">http://example.com?x=&amp;y=</a>'),
'filter-urlize03': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": mark_safe("a &amp; b")}, 'a &amp; b'),
'filter-urlize04': ('{{ a|urlize }}', {"a": mark_safe("a &amp; b")}, 'a &amp; b'),
@@ -108,8 +108,12 @@ def get_filter_tests():
'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": "<script>alert('foo')</script>"}, "<script>alert('foo')</script>"),
'filter-urlize06': ('{{ a|urlize }}', {"a": "<script>alert('foo')</script>"}, '&lt;script&gt;alert(&#39;foo&#39;)&lt;/script&gt;'),
- 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'),
- 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&y=')}, u'&quot;Unsafe&quot; <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&y=" rel="nofollow">http:...</a>'),
+ # mailto: testing for urlize
+ 'filter-urlize07': ('{{ a|urlize }}', {"a": "Email me at me@example.com"}, 'Email me at <a href="mailto:me@example.com">me@example.com</a>'),
+ 'filter-urlize08': ('{{ a|urlize }}', {"a": "Email me at <me@example.com>"}, 'Email me at &lt;<a href="mailto:me@example.com">me@example.com</a>&gt;'),
+
+ 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&amp;y=')}, u'"Unsafe" <a href="http://example.com/x=&y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&amp;y=" rel="nofollow">http:...</a>'),
+ 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('&quot;Safe&quot; http://example.com?x=&amp;y=')}, u'&quot;Unsafe&quot; <a href="http://example.com/x=&amp;y=" rel="nofollow">http:...</a> &quot;Safe&quot; <a href="http://example.com?x=&amp;y=" rel="nofollow">http:...</a>'),
'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"),
'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a &amp; b")}, "3 3"),
@@ -240,7 +244,7 @@ def get_filter_tests():
'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.
+ # 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'),
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
index 9e9033f975..aef6f504b1 100644
--- a/tests/regressiontests/templates/tests.py
+++ b/tests/regressiontests/templates/tests.py
@@ -736,7 +736,7 @@ class Templates(unittest.TestCase):
'i18n09': ('{% load i18n %}{% trans "Page not found" noop %}', {'LANGUAGE_CODE': 'de'}, "Page not found"),
# translation of a variable with a translated filter
- 'i18n10': ('{{ bool|yesno:_("ja,nein") }}', {'bool': True}, 'ja'),
+ 'i18n10': ('{{ bool|yesno:_("yes,no,maybe") }}', {'bool': True, 'LANGUAGE_CODE': 'de'}, 'Ja'),
# translation of a variable with a non-translated filter
'i18n11': ('{{ bool|yesno:"ja,nein" }}', {'bool': True}, 'ja'),