From 7edd912cfbf91e8c7cc8bb742645973b82a9ab5a Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Thu, 2 Jul 2015 14:23:28 -0400 Subject: [PATCH] Used assertRaisesMessage in managers_regress tests. --- tests/managers_regress/tests.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/tests/managers_regress/tests.py b/tests/managers_regress/tests.py index c83c40055f..cd9898ae63 100644 --- a/tests/managers_regress/tests.py +++ b/tests/managers_regress/tests.py @@ -66,35 +66,29 @@ class ManagersRegressionTests(TestCase): def test_abstract_manager(self): # Accessing the manager on an abstract model should # raise an attribute error with an appropriate message. - try: + # This error message isn't ideal, but if the model is abstract and + # a lot of the class instantiation logic isn't invoked; if the + # manager is implied, then we don't get a hook to install the + # error-raising manager. + msg = "type object 'AbstractBase3' has no attribute 'objects'" + with self.assertRaisesMessage(AttributeError, msg): AbstractBase3.objects.all() - self.fail('Should raise an AttributeError') - except AttributeError as e: - # This error message isn't ideal, but if the model is abstract and - # a lot of the class instantiation logic isn't invoked; if the - # manager is implied, then we don't get a hook to install the - # error-raising manager. - self.assertEqual(str(e), "type object 'AbstractBase3' has no attribute 'objects'") def test_custom_abstract_manager(self): # Accessing the manager on an abstract model with an custom # manager should raise an attribute error with an appropriate # message. - try: + msg = "Manager isn't available; AbstractBase2 is abstract" + with self.assertRaisesMessage(AttributeError, msg): AbstractBase2.restricted.all() - self.fail('Should raise an AttributeError') - except AttributeError as e: - self.assertEqual(str(e), "Manager isn't available; AbstractBase2 is abstract") def test_explicit_abstract_manager(self): # Accessing the manager on an abstract model with an explicit # manager should raise an attribute error with an appropriate # message. - try: + msg = "Manager isn't available; AbstractBase1 is abstract" + with self.assertRaisesMessage(AttributeError, msg): AbstractBase1.objects.all() - self.fail('Should raise an AttributeError') - except AttributeError as e: - self.assertEqual(str(e), "Manager isn't available; AbstractBase1 is abstract") @override_settings(TEST_SWAPPABLE_MODEL='managers_regress.Parent') def test_swappable_manager(self):