diff options
| author | Jacob R. Rothenbuhler <jakerothenbuhler@gmail.com> | 2014-04-14 15:13:49 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2014-04-14 15:55:10 -0400 |
| commit | 17c18844561431aabed89c3bd48de951db7d13ab (patch) | |
| tree | e706e99fda9117d12e89cfe66c262dd4b323ba83 /django | |
| parent | 09af48c70fb5cc652ea109487015472e9ef984df (diff) | |
Fixed #22369 -- Added count parameter to assertTemplateUsed
Diffstat (limited to 'django')
| -rw-r--r-- | django/test/testcases.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/django/test/testcases.py b/django/test/testcases.py index 95d0d8e399..a7986dd028 100644 --- a/django/test/testcases.py +++ b/django/test/testcases.py @@ -521,7 +521,7 @@ class SimpleTestCase(unittest.TestCase): None] return None, template_names, msg_prefix - def assertTemplateUsed(self, response=None, template_name=None, msg_prefix=''): + def assertTemplateUsed(self, response=None, template_name=None, msg_prefix='', count=None): """ Asserts that the template with the provided name was used in rendering the response. Also usable as context manager. @@ -540,6 +540,12 @@ class SimpleTestCase(unittest.TestCase): " the response. Actual template(s) used: %s" % (template_name, ', '.join(template_names))) + if count is not None: + self.assertEqual(template_names.count(template_name), count, + msg_prefix + "Template '%s' was expected to be rendered %d " + "time(s) but was actually rendered %d time(s)." % + (template_name, count, template_names.count(template_name))) + def assertTemplateNotUsed(self, response=None, template_name=None, msg_prefix=''): """ Asserts that the template with the provided name was NOT used in |
