diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2014-01-20 10:45:21 +0800 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2014-01-20 10:45:21 +0800 |
| commit | d818e0c9b2b88276cc499974f9eee893170bf0a8 (patch) | |
| tree | 13ef631f7ba50bf81fa36f484abf925ba8172651 /tests/admin_views | |
| parent | 6e7bd0b63bd01949ac4fd647f2597639bed0c3a2 (diff) | |
Fixed #16905 -- Added extensible checks (nee validation) framework
This is the result of Christopher Medrela's 2013 Summer of Code project.
Thanks also to Preston Holmes, Tim Graham, Anssi Kääriäinen, Florian
Apolloner, and Alex Gaynor for review notes along the way.
Also: Fixes #8579, fixes #3055, fixes #19844.
Diffstat (limited to 'tests/admin_views')
| -rw-r--r-- | tests/admin_views/tests.py | 31 |
1 files changed, 21 insertions, 10 deletions
diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index d01a37725a..60280655b6 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -8,6 +8,7 @@ import unittest from django.conf import settings, global_settings from django.core import mail +from django.core.checks import Error from django.core.files import temp as tempfile from django.core.exceptions import ImproperlyConfigured from django.core.urlresolvers import reverse, NoReverseMatch @@ -4675,17 +4676,27 @@ class AdminViewOnSiteTests(TestCase): self.assertEqual(['Children must share a family name with their parents in this contrived test case'], error_set.get('__all__')) - def test_validate(self): + def test_check(self): "Ensure that the view_on_site value is either a boolean or a callable" - CityAdmin.view_on_site = True - CityAdmin.validate(City) - CityAdmin.view_on_site = False - CityAdmin.validate(City) - CityAdmin.view_on_site = lambda obj: obj.get_absolute_url() - CityAdmin.validate(City) - CityAdmin.view_on_site = [] - with self.assertRaisesMessage(ImproperlyConfigured, 'CityAdmin.view_on_site is not a callable or a boolean value.'): - CityAdmin.validate(City) + try: + CityAdmin.view_on_site = True + self.assertEqual(CityAdmin.check(City), []) + CityAdmin.view_on_site = False + self.assertEqual(CityAdmin.check(City), []) + CityAdmin.view_on_site = lambda obj: obj.get_absolute_url() + self.assertEqual(CityAdmin.check(City), []) + CityAdmin.view_on_site = [] + self.assertEqual(CityAdmin.check(City), [ + Error( + '"view_on_site" is not a callable or a boolean value.', + hint=None, + obj=CityAdmin, + id='admin.E025', + ), + ]) + finally: + # Restore the original values for the benefit of other tests. + CityAdmin.view_on_site = True def test_false(self): "Ensure that the 'View on site' button is not displayed if view_on_site is False" |
