From 57f4b3ce373c1c1fef794507a16410d40aebdda6 Mon Sep 17 00:00:00 2001 From: Anton Samarchyan Date: Mon, 19 Jun 2017 14:50:12 -0400 Subject: [PATCH] Added tests for AdminSite's add/disable/get action methods. --- tests/admin_views/test_adminsite.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/admin_views/test_adminsite.py b/tests/admin_views/test_adminsite.py index 0885615353..5359a95dce 100644 --- a/tests/admin_views/test_adminsite.py +++ b/tests/admin_views/test_adminsite.py @@ -1,7 +1,8 @@ from django.conf.urls import url from django.contrib import admin +from django.contrib.admin.actions import delete_selected from django.contrib.auth.models import User -from django.test import TestCase, override_settings +from django.test import SimpleTestCase, TestCase, override_settings from django.test.client import RequestFactory from django.urls import reverse @@ -73,3 +74,28 @@ class SiteEachContextTest(TestCase): self.assertEqual(user['admin_url'], '/test_admin/admin/auth/user/') self.assertEqual(user['add_url'], '/test_admin/admin/auth/user/add/') self.assertEqual(user['name'], 'Users') + + +class SiteActionsTests(SimpleTestCase): + def setUp(self): + self.site = admin.AdminSite() + + def test_add_action(self): + def test_action(): + pass + self.site.add_action(test_action) + self.assertEqual(self.site.get_action('test_action'), test_action) + + def test_disable_action(self): + action_name = 'delete_selected' + self.assertEqual(self.site._actions[action_name], delete_selected) + self.site.disable_action(action_name) + with self.assertRaises(KeyError): + self.site._actions[action_name] + + def test_get_action(self): + """AdminSite.get_action() returns an action even if it's disabled.""" + action_name = 'delete_selected' + self.assertEqual(self.site.get_action(action_name), delete_selected) + self.site.disable_action(action_name) + self.assertEqual(self.site.get_action(action_name), delete_selected)