# -*- coding: UTF-8 -*-

# Copyright (C) 2020 Avencall
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA..

import unittest

from hamcrest import assert_that, equal_to
from mock import Mock
from xivo_dao.alchemy.labels import Labels

from xivo_confd.plugins.label.resource import LabelList


class TestAgentItem(unittest.TestCase):
    def setUp(self):
        self.service = Mock()
        self.admin_group = LabelList(self.service)
        self.admin_group.parser = Mock()
        self.admin_group.persistor = Mock()

    def test_get(self):
        ag = [Labels(id=1, display_name='Admin Group One', description="this is a label")]
        self.service.search.return_value = (1, ag)

        res = self.admin_group.get()

        assert_that(res['items'][0]['id'], equal_to(1))
        assert_that(res['items'][0]['display_name'], equal_to('Admin Group One'))
        assert_that(res['items'][0]['description'], equal_to('this is a label'))
        assert_that(res['total'], equal_to(1))
