summaryrefslogtreecommitdiff
path: root/tests/modeladmin
diff options
context:
space:
mode:
authorBaptiste Mispelon <bmispelon@gmail.com>2014-03-03 15:38:07 +0100
committerBaptiste Mispelon <bmispelon@gmail.com>2014-03-03 15:45:48 +0100
commit0dffaf9c25b9b69f690fc2783c2d528997f9ece8 (patch)
treed10c8b46a3bf38dd3dd5564ecef0bcfa3944d904 /tests/modeladmin
parenteae4f16177f7362509e3579836424f177c8502bf (diff)
Fixed broken tests on Python 3 after 3c5fc708f1a8f60c05182869f6f3ec13697bbcf2.
Diffstat (limited to 'tests/modeladmin')
-rw-r--r--tests/modeladmin/tests.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py
index f6a250db09..146c078e59 100644
--- a/tests/modeladmin/tests.py
+++ b/tests/modeladmin/tests.py
@@ -552,6 +552,20 @@ class CheckTestCase(TestCase):
]
self.assertEqual(errors, expected)
+ def assertIsInvalidRegexp(self, model_admin, model, msg,
+ id=None, hint=None, invalid_obj=None):
+ """
+ Same as assertIsInvalid but treats the given msg as a regexp.
+ """
+ invalid_obj = invalid_obj or model_admin
+ errors = model_admin.check(model=model)
+ self.assertEqual(len(errors), 1)
+ error = errors[0]
+ self.assertEqual(error.hint, hint)
+ self.assertEqual(error.obj, invalid_obj)
+ self.assertEqual(error.id, id)
+ self.assertRegexpMatches(error.msg, msg)
+
def assertIsValid(self, model_admin, model):
errors = model_admin.check(model=model)
expected = []
@@ -1302,9 +1316,9 @@ class InlinesCheckTests(CheckTestCase):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertIsInvalid(
+ self.assertIsInvalidRegexp(
ValidationTestModelAdmin, ValidationTestModel,
- "'modeladmin.tests.ValidationTestInline' must inherit from 'BaseModelAdmin'.",
+ r"'.*\.ValidationTestInline' must inherit from 'BaseModelAdmin'\.",
'admin.E104')
def test_missing_model_field(self):
@@ -1314,9 +1328,9 @@ class InlinesCheckTests(CheckTestCase):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertIsInvalid(
+ self.assertIsInvalidRegexp(
ValidationTestModelAdmin, ValidationTestModel,
- "'modeladmin.tests.ValidationTestInline' must have a 'model' attribute.",
+ r"'.*\.ValidationTestInline' must have a 'model' attribute\.",
'admin.E105')
def test_invalid_model_type(self):
@@ -1332,9 +1346,9 @@ class InlinesCheckTests(CheckTestCase):
class ValidationTestModelAdmin(ModelAdmin):
inlines = [ValidationTestInline]
- self.assertIsInvalid(
+ self.assertIsInvalidRegexp(
ValidationTestModelAdmin, ValidationTestModel,
- "The value of 'modeladmin.tests.ValidationTestInline.model' must be a Model.",
+ r"The value of '.*\.ValidationTestInline.model' must be a Model\.",
'admin.E106')
def test_valid_case(self):