From d05709821cf6ff77e00871d6fac3eb43356d44d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Guimar=C3=A3es?= Date: Fri, 5 Dec 2014 12:25:10 -0200 Subject: [PATCH] Refs #23947 -- Made a modeladmin test cleanup after itself. --- tests/modeladmin/tests.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/tests/modeladmin/tests.py b/tests/modeladmin/tests.py index 93cb58a42c..a0dfb2a72d 100644 --- a/tests/modeladmin/tests.py +++ b/tests/modeladmin/tests.py @@ -1625,10 +1625,15 @@ class ModelAdminPermissionTests(TestCase): self.assertTrue(ma.has_module_permission(request)) request.user = self.MockDeleteUser() self.assertTrue(ma.has_module_permission(request)) - ma.opts.app_label = "anotherapp" - request.user = self.MockAddUser() - self.assertFalse(ma.has_module_permission(request)) - request.user = self.MockChangeUser() - self.assertFalse(ma.has_module_permission(request)) - request.user = self.MockDeleteUser() - self.assertFalse(ma.has_module_permission(request)) + + original_app_label = ma.opts.app_label + ma.opts.app_label = 'anotherapp' + try: + request.user = self.MockAddUser() + self.assertFalse(ma.has_module_permission(request)) + request.user = self.MockChangeUser() + self.assertFalse(ma.has_module_permission(request)) + request.user = self.MockDeleteUser() + self.assertFalse(ma.has_module_permission(request)) + finally: + ma.opts.app_label = original_app_label