From 0dffaf9c25b9b69f690fc2783c2d528997f9ece8 Mon Sep 17 00:00:00 2001 From: Baptiste Mispelon Date: Mon, 3 Mar 2014 15:38:07 +0100 Subject: [PATCH] Fixed broken tests on Python 3 after 3c5fc708f1a8f60c05182869f6f3ec13697bbcf2. --- tests/modeladmin/tests.py | 26 ++++++++++++++++++++------ 1 file 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):