Exemplo n.º 1
0
    def test_register_raises_management_command_admin_already_registered_exception(
        self, ) -> None:
        """register method must raise "ManagementCommandAdminAlreadyRegisteredError"."""  # noqa: D403,E501
        registry.register(TestManagementCommandAdmin)

        with self.assertRaises(ManagementCommandAdminAlreadyRegisteredError):
            registry.register(TestManagementCommandAdmin)
Exemplo n.º 2
0
 def setUpTestData(cls) -> None:
     """Set up non-modified objects used by all test methods."""
     registry.register(TestManagementCommandAdmin)
     group = Group.objects.create(name="Test")
     Command.objects.create(
         command="tests.test_loader.TestManagementCommandAdmin", group=group
     )
Exemplo n.º 3
0
    def test_unregister(self) -> None:
        """unregister method must remove command from registry."""  # noqa: D403
        registry.register(TestManagementCommandAdmin)
        registry.unregister(TestManagementCommandAdmin)

        self.assertDictEqual(
            d1=registry._registry,
            d2={},
        )
Exemplo n.º 4
0
    def test_choices(self) -> None:
        """choices property must contain commands choices for admin."""  # noqa: D403
        registry.register(TestManagementCommandAdmin)

        self.assertListEqual(
            list1=registry.choices,
            list2=[("tests.test_registry.TestManagementCommandAdmin",
                    "Test Command")],
        )
Exemplo n.º 5
0
    def test_register(self) -> None:
        """register method must add command to registry."""  # noqa: D403
        registry.register(TestManagementCommandAdmin)

        self.assertDictEqual(
            d1=registry._registry,
            d2={
                "tests.test_registry.TestManagementCommandAdmin":
                TestManagementCommandAdmin  # noqa: E501
            },
        )
Exemplo n.º 6
0
 def setUpTestData(cls) -> None:
     """Set up non-modified objects used by all test methods."""
     registry.register(TestManagementCommandAdmin)
     user = User.objects.create_user(
         username="******", password=User.objects.make_random_password())
     group = Group.objects.create(name="Test")
     command = Command.objects.create(
         command="tests.test_views.TestManagementCommandAdmin")
     Command.objects.create(
         command="tests.test_views.TestManagementCommandAdminInGroup",
         group=group)
     CommandGroupPermission.objects.create(user=user, group=group)
     CommandPermission.objects.create(user=user, command=command)
Exemplo n.º 7
0
 def test_register_raises_not_management_command_admin_exception(
         self) -> None:
     """register method must raise "NotManagementCommandAdminError"."""  # noqa: D403
     with self.assertRaises(NotManagementCommandAdminError):
         registry.register(object)  # type: ignore
Exemplo n.º 8
0
    def test_clean(self) -> None:
        """clean method must remove all command from registry."""  # noqa: D403
        registry.register(TestManagementCommandAdmin)
        registry.clean()

        self.assertDictEqual(d1=registry._registry, d2={})