From 0a9b7519582bc358be10bb374bfbdfe237e09578 Mon Sep 17 00:00:00 2001 From: Malcolm Tredinnick Date: Mon, 4 Feb 2008 05:45:17 +0000 Subject: queryset-refactor: Merged changes from trunk up to [7085]. git-svn-id: http://code.djangoproject.com/svn/django/branches/queryset-refactor@7086 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- tests/modeltests/signals/models.py | 35 +++++++++++++++++++++++++-- tests/regressiontests/datastructures/tests.py | 13 ++++++++++ tests/regressiontests/templates/filters.py | 14 +++++++---- tests/regressiontests/templates/tests.py | 2 +- 4 files changed, 56 insertions(+), 8 deletions(-) (limited to 'tests') 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() [] +>>> 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/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 & b")}, u"A & B A & B"), 'filter-upper02': ('{{ a|upper }} {{ b|upper }}', {"a": "a & b", "b": mark_safe("a & b")}, u"A & B A &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'http://example.com/x=&y= http://example.com?x=&y='), - 'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'http://example.com/x=&y= http://example.com?x=&y='), + 'filter-urlize01': ('{% autoescape off %}{{ a|urlize }} {{ b|urlize }}{% endautoescape %}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'http://example.com/?x=&y= http://example.com?x=&y='), + 'filter-urlize02': ('{{ a|urlize }} {{ b|urlize }}', {"a": "http://example.com/?x=&y=", "b": mark_safe("http://example.com?x=&y=")}, u'http://example.com/?x=&y= http://example.com?x=&y='), 'filter-urlize03': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": mark_safe("a & b")}, 'a & b'), 'filter-urlize04': ('{{ a|urlize }}', {"a": mark_safe("a & b")}, 'a & b'), @@ -108,8 +108,12 @@ def get_filter_tests(): 'filter-urlize05': ('{% autoescape off %}{{ a|urlize }}{% endautoescape %}', {"a": ""}, ""), 'filter-urlize06': ('{{ a|urlize }}', {"a": ""}, '<script>alert('foo')</script>'), - 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" http:... "Safe" http:...'), - 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" http:... "Safe" http:...'), + # mailto: testing for urlize + 'filter-urlize07': ('{{ a|urlize }}', {"a": "Email me at me@example.com"}, 'Email me at me@example.com'), + 'filter-urlize08': ('{{ a|urlize }}', {"a": "Email me at "}, 'Email me at <me@example.com>'), + + 'filter-urlizetrunc01': ('{% autoescape off %}{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}{% endautoescape %}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" http:... "Safe" http:...'), + 'filter-urlizetrunc02': ('{{ a|urlizetrunc:"8" }} {{ b|urlizetrunc:"8" }}', {"a": '"Unsafe" http://example.com/x=&y=', "b": mark_safe('"Safe" http://example.com?x=&y=')}, u'"Unsafe" http:... "Safe" http:...'), 'filter-wordcount01': ('{% autoescape off %}{{ a|wordcount }} {{ b|wordcount }}{% endautoescape %}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), 'filter-wordcount02': ('{{ a|wordcount }} {{ b|wordcount }}', {"a": "a & b", "b": mark_safe("a & b")}, "3 3"), @@ -240,7 +244,7 @@ def get_filter_tests(): 'chaining13': ('{{ a|safe|force_escape }}', {"a": "a < b"}, "a < b"), 'chaining14': ('{% autoescape off %}{{ a|safe|force_escape }}{% endautoescape %}', {"a": "a < b"}, "a < 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 & me'), 'autoescape-stringfilter02': (r'{% autoescape off %}{{ unsafe|capfirst }}{% endautoescape %}', {'unsafe': UnsafeClass()}, 'You & me'), 'autoescape-stringfilter03': (r'{{ safe|capfirst }}', {'safe': SafeClass()}, 'You > 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'), -- cgit v1.3