Beispiel #1
0
    def test_chpasswd_success(self, mock_log, mock_libuser):

        """
        unittest to validate chpasswd() method with success scenario
        mock_log: mock of wok_log imported in model.users
        mock_libuser: mock of libuser imported in model.users
        """
        mock_adm = mock_libuser.admin()
        mock_adm.lookupUserByName.return_value = 'dummy_user'
        user_model = UserModel()
        user_model.chpasswd('user1', 'password')
        mock_adm.lookupUserByName.assert_called_once_with('user1')
        mock_adm.setpassUser.assert_called_once_with(
            'dummy_user', 'password', False)
        self.assertFalse(mock_log.error.called,
                         msg='Unexpected call to mock_log.error')
Beispiel #2
0
    def test_delete_success(self, mock_log, mock_delete_user,
                            mock_get_usr_obj, mock_get_grp_by_gid,
                            mock_delete_group):

        """
        unittest to validate delete() method success scenario
        mock_log: mock of wok_log imported in model.users
        mock_libuser: mock of libuser imported in model.users
        mock_delete_user: mock of delete_user() in model.users
        mock_get_usr_obj: mock of get_user_obj() in model.users
        mock_get_grp_by_gid: mock of get_group_obj_by_gid()  in model.users
        mock_delete_group: mock of delete_group() in model.users
        """
        user = UserModel()
        user.delete('user1')
        mock_get_usr_obj.assert_called_once_with('user1')
        mock_delete_user.assert_called_once_with('user1')
        self.assertTrue(mock_get_grp_by_gid.called,
                        msg='Expected call to mock_get_grp_by_gid.Not Called')