diff options
| author | Jason Pellerin <jpellerin@gmail.com> | 2006-09-08 16:35:39 +0000 |
|---|---|---|
| committer | Jason Pellerin <jpellerin@gmail.com> | 2006-09-08 16:35:39 +0000 |
| commit | 84f7a2133c4d553a234165bb8cbfaf70681bb028 (patch) | |
| tree | 53d08c1ffc275a4e1d62d7f48ea81172a5919051 /tests/regressiontests | |
| parent | ae3896cb74d4bc42acaf6fade0d2a57e28045b2a (diff) | |
[multi-db] Merge trunk to [3737]. Some tests still failing.
git-svn-id: http://code.djangoproject.com/svn/django/branches/multiple-db-support@3739 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'tests/regressiontests')
| -rw-r--r-- | tests/regressiontests/templates/tests.py | 54 | ||||
| -rw-r--r-- | tests/regressiontests/thread_isolation/tests.py | 10 |
2 files changed, 43 insertions, 21 deletions
diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py index 2d1ce192ef..5a8dd2d6a2 100644 --- a/tests/regressiontests/templates/tests.py +++ b/tests/regressiontests/templates/tests.py @@ -84,7 +84,7 @@ class Templates(unittest.TestCase): 'basic-syntax03': ("{{ first }} --- {{ second }}", {"first" : 1, "second" : 2}, "1 --- 2"), # Fail silently when a variable is not found in the current context - 'basic-syntax04': ("as{{ missing }}df", {}, "asINVALIDdf"), + 'basic-syntax04': ("as{{ missing }}df", {}, ("asdf","asINVALIDdf")), # A variable may not contain more than one word 'basic-syntax06': ("{{ multi word variable }}", {}, template.TemplateSyntaxError), @@ -100,7 +100,7 @@ class Templates(unittest.TestCase): 'basic-syntax10': ("{{ var.otherclass.method }}", {"var": SomeClass()}, "OtherClass.method"), # Fail silently when a variable's attribute isn't found - 'basic-syntax11': ("{{ var.blech }}", {"var": SomeClass()}, "INVALID"), + 'basic-syntax11': ("{{ var.blech }}", {"var": SomeClass()}, ("","INVALID")), # Raise TemplateSyntaxError when trying to access a variable beginning with an underscore 'basic-syntax12': ("{{ var.__dict__ }}", {"var": SomeClass()}, template.TemplateSyntaxError), @@ -116,10 +116,10 @@ class Templates(unittest.TestCase): 'basic-syntax18': ("{{ foo.bar }}", {"foo" : {"bar" : "baz"}}, "baz"), # Fail silently when a variable's dictionary key isn't found - 'basic-syntax19': ("{{ foo.spam }}", {"foo" : {"bar" : "baz"}}, "INVALID"), + 'basic-syntax19': ("{{ foo.spam }}", {"foo" : {"bar" : "baz"}}, ("","INVALID")), # Fail silently when accessing a non-simple method - 'basic-syntax20': ("{{ var.method2 }}", {"var": SomeClass()}, "INVALID"), + 'basic-syntax20': ("{{ var.method2 }}", {"var": SomeClass()}, ("","INVALID")), # Basic filter usage 'basic-syntax21': ("{{ var|upper }}", {"var": "Django is the greatest!"}, "DJANGO IS THE GREATEST!"), @@ -158,7 +158,7 @@ class Templates(unittest.TestCase): 'basic-syntax32': (r'{{ var|yesno:"yup,nup,mup" }} {{ var|yesno }}', {"var": True}, 'yup yes'), # Fail silently for methods that raise an exception with a "silent_variable_failure" attribute - 'basic-syntax33': (r'1{{ var.method3 }}2', {"var": SomeClass()}, "1INVALID2"), + 'basic-syntax33': (r'1{{ var.method3 }}2', {"var": SomeClass()}, ("12", "1INVALID2")), # In methods that raise an exception without a "silent_variable_attribute" set to True, # the exception propogates @@ -464,6 +464,14 @@ class Templates(unittest.TestCase): # translation of a constant string 'i18n13': ('{{ _("Page not found") }}', {'LANGUAGE_CODE': 'de'}, 'Seite nicht gefunden'), + ### HANDLING OF TEMPLATE_TAG_IF_INVALID ################################### + + 'invalidstr01': ('{{ var|default:"Foo" }}', {}, ('Foo','INVALID')), + 'invalidstr02': ('{{ var|default_if_none:"Foo" }}', {}, ('','INVALID')), + 'invalidstr03': ('{% for v in var %}({{ v }}){% endfor %}', {}, ''), + 'invalidstr04': ('{% if var %}Yes{% else %}No{% endif %}', {}, 'No'), + 'invalidstr04': ('{% if var|default:"Foo" %}Yes{% else %}No{% endif %}', {}, 'Yes'), + ### MULTILINE ############################################################# 'multiline01': (""" @@ -507,7 +515,7 @@ class Templates(unittest.TestCase): '{{ item.foo }}' + \ '{% endfor %},' + \ '{% endfor %}', - {}, 'INVALID:INVALIDINVALIDINVALIDINVALIDINVALIDINVALIDINVALID,'), + {}, ''), ### TEMPLATETAG TAG ####################################################### 'templatetag01': ('{% templatetag openblock %}', {}, '{%'), @@ -592,30 +600,44 @@ class Templates(unittest.TestCase): old_td, settings.TEMPLATE_DEBUG = settings.TEMPLATE_DEBUG, False # Set TEMPLATE_STRING_IF_INVALID to a known string - old_invalid, settings.TEMPLATE_STRING_IF_INVALID = settings.TEMPLATE_STRING_IF_INVALID, 'INVALID' + old_invalid = settings.TEMPLATE_STRING_IF_INVALID for name, vals in tests: install() + + if isinstance(vals[2], tuple): + normal_string_result = vals[2][0] + invalid_string_result = vals[2][1] + else: + normal_string_result = vals[2] + invalid_string_result = vals[2] + if 'LANGUAGE_CODE' in vals[1]: activate(vals[1]['LANGUAGE_CODE']) else: activate('en-us') - try: - output = loader.get_template(name).render(template.Context(vals[1])) - except Exception, e: - if e.__class__ != vals[2]: - failures.append("Template test: %s -- FAILED. Got %s, exception: %s" % (name, e.__class__, e)) - continue + + for invalid_str, result in [('', normal_string_result), + ('INVALID', invalid_string_result)]: + settings.TEMPLATE_STRING_IF_INVALID = invalid_str + try: + output = loader.get_template(name).render(template.Context(vals[1])) + except Exception, e: + if e.__class__ != result: + failures.append("Template test (TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Got %s, exception: %s" % (invalid_str, name, e.__class__, e)) + continue + if output != result: + failures.append("Template test (TEMPLATE_STRING_IF_INVALID='%s'): %s -- FAILED. Expected %r, got %r" % (invalid_str, name, result, output)) + if 'LANGUAGE_CODE' in vals[1]: deactivate() - if output != vals[2]: - failures.append("Template test: %s -- FAILED. Expected %r, got %r" % (name, vals[2], output)) + loader.template_source_loaders = old_template_loaders deactivate() settings.TEMPLATE_DEBUG = old_td settings.TEMPLATE_STRING_IF_INVALID = old_invalid - self.assertEqual(failures, []) + self.assertEqual(failures, [], '\n'.join(failures)) if __name__ == "__main__": unittest.main() diff --git a/tests/regressiontests/thread_isolation/tests.py b/tests/regressiontests/thread_isolation/tests.py index f677c27bf8..39c141720a 100644 --- a/tests/regressiontests/thread_isolation/tests.py +++ b/tests/regressiontests/thread_isolation/tests.py @@ -34,8 +34,9 @@ except ImportError: # Import copy of _thread_local.py from Python 2.4 from django.utils._threading_local import local - # helpers +EV = threading.Event() + class LocalSettings: """Settings holder that allows thread-local overrides of defaults. """ @@ -69,7 +70,7 @@ def thread_two(func, *arg): debug("t2 ODB: %s", settings.OTHER_DATABASES) debug("t2 waiting") - ev.wait(2.0) + EV.wait(2.0) func(*arg) debug("t2 complete") t2 = threading.Thread(target=start) @@ -94,7 +95,7 @@ def thread_three(func, *arg): connection.settings.DATABASE_NAME) debug("t3 waiting") - ev.wait(2.0) + EV.wait(2.0) func(*arg) debug("t3 complete") t3 = threading.Thread(target=start) @@ -113,7 +114,6 @@ def start_response(code, headers): class TestThreadIsolation(unittest.TestCase): # event used to synchronize threads so we can be sure they are running # together - ev = threading.Event() lock = threading.RLock() errors = [] @@ -235,7 +235,7 @@ class TestThreadIsolation(unittest.TestCase): t3 = thread_three(MockHandler(self.request_three), env, start_response) try: - self.ev.set() + EV.set() MockHandler(self.request_one)(env, start_response) finally: t2.join() |
