Example #1
0
    def test_attributes_of_created_user(self, mock_user, mock_group,
                                        mock_permission):
        """
        Tests username and last_name of the created admin user.
        """
        admin_user = MagicMock(username="******", last_name="Administrator")
        manager = UserManager()
        manager.get = MagicMock(side_effect=ObjectDoesNotExist)
        manager.model = mock_user

        staff_group = MagicMock(name="Staff")
        mock_group.objects.get_or_create = MagicMock(return_value=(staff_group,
                                                                   True))
        mock_permission.get = MagicMock()

        manager.create_or_reset_admin_user()

        self.assertEqual(
            admin_user.username,
            "admin",
            "The username of a new created admin should be 'admin'.",
        )
        self.assertEqual(
            admin_user.last_name,
            "Administrator",
            "The last_name of a new created admin should be 'Administrator'.",
        )
    def test_attributes_of_created_user(self, mock_user, mock_group, mock_permission):
        """
        Tests username and last_name of the created admin user.
        """
        admin_user = MagicMock(username="******", last_name="Administrator")
        manager = UserManager()
        manager.get = MagicMock(side_effect=ObjectDoesNotExist)
        manager.model = mock_user

        staff_group = MagicMock(name="Staff")
        mock_group.objects.get_or_create = MagicMock(return_value=(staff_group, True))
        mock_permission.get = MagicMock()

        manager.create_or_reset_admin_user()

        self.assertEqual(
            admin_user.username,
            "admin",
            "The username of a new created admin should be 'admin'.",
        )
        self.assertEqual(
            admin_user.last_name,
            "Administrator",
            "The last_name of a new created admin should be 'Administrator'.",
        )
Example #3
0
    def test_add_admin_group(self, mock_group, mock_permission):
        """
        Tests that the Group with pk=2 (Admin group) is added to the admin.
        """
        admin_user = MagicMock()
        manager = UserManager()
        manager.get = MagicMock(return_value=(admin_user))

        manager.create_or_reset_admin_user()

        admin_user.groups.add.assert_called_once_with(
            2)  # the admin should be added to the admin group with pk=2
    def test_add_admin_group(self, mock_group, mock_permission):
        """
        Tests that the Group with pk=2 (Admin group) is added to the admin.
        """
        admin_user = MagicMock()
        manager = UserManager()
        manager.get = MagicMock(return_value=(admin_user))

        manager.create_or_reset_admin_user()

        admin_user.groups.add.assert_called_once_with(
            2
        )  # the admin should be added to the admin group with pk=2
    def test_password_set_to_admin(self, mock_group, mock_permission):
        """
        Tests that the password of the admin is set to 'admin'.
        """
        admin_user = MagicMock()
        manager = UserManager()
        manager.get = MagicMock(return_value=(admin_user))

        staff_group = MagicMock(name="Staff")
        mock_group.objects.get_or_create = MagicMock(return_value=(staff_group, True))
        mock_permission.get = MagicMock()

        manager.create_or_reset_admin_user()

        self.assertEqual(admin_user.default_password, "admin")
        admin_user.save.assert_called_once_with(skip_autoupdate=True)
Example #6
0
    def test_password_set_to_admin(self, mock_group, mock_permission):
        """
        Tests that the password of the admin is set to 'admin'.
        """
        admin_user = MagicMock()
        manager = UserManager()
        manager.get = MagicMock(return_value=(admin_user))

        staff_group = MagicMock(name="Staff")
        mock_group.objects.get_or_create = MagicMock(return_value=(staff_group,
                                                                   True))
        mock_permission.get = MagicMock()

        manager.create_or_reset_admin_user(skip_autoupdate=True)

        self.assertEqual(admin_user.default_password, "admin")
        admin_user.save.assert_called_once_with(skip_autoupdate=True)
    def test_return_value(self, mock_user, mock_group, mock_permission):
        """
        Tests that the method returns True when a user is created.
        """
        manager = UserManager()
        manager.get = MagicMock(side_effect=ObjectDoesNotExist)
        manager.model = mock_user

        staff_group = MagicMock(name="Staff")
        mock_group.objects.get_or_create = MagicMock(return_value=(staff_group, True))
        mock_permission.get = MagicMock()

        self.assertEqual(
            manager.create_or_reset_admin_user(),
            True,
            "The method create_or_reset_admin_user should return True when a "
            "new user is created.",
        )
Example #8
0
    def test_return_value(self, mock_user, mock_group, mock_permission):
        """
        Tests that the method returns True when a user is created.
        """
        manager = UserManager()
        manager.get = MagicMock(side_effect=ObjectDoesNotExist)
        manager.model = mock_user

        staff_group = MagicMock(name="Staff")
        mock_group.objects.get_or_create = MagicMock(return_value=(staff_group,
                                                                   True))
        mock_permission.get = MagicMock()

        self.assertEqual(
            manager.create_or_reset_admin_user(),
            True,
            "The method create_or_reset_admin_user should return True when a "
            "new user is created.",
        )