# -*- coding: utf-8 -*-
#
# Copyright (C) 2026 XiVO Solutions
#
# 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, see <http://www.gnu.org/licenses/>

import unittest

from hamcrest import assert_that
from hamcrest import contains_inanyorder
from hamcrest import equal_to
from mock import Mock

from xivo_dird.dao.user_label import UserLabelDAO


class TestUserLabelDAO(unittest.TestCase):

    def setUp(self):
        self.session = Mock()
        self.query = self.session.query.return_value
        self.query.join.return_value = self.query
        self.query.filter.return_value = self.query
        self.dao = UserLabelDAO(Mock(return_value=self.session))

    def test_that_a_uuid_resolves_to_its_assigned_label_ids(self):
        self.query.all.return_value = [Mock(label_id=1), Mock(label_id=3)]

        result = self.dao.label_ids_for_user('some-uuid')

        assert_that(result, contains_inanyorder(1, 3))

    def test_that_a_uuid_without_labels_resolves_to_an_empty_set(self):
        self.query.all.return_value = []

        result = self.dao.label_ids_for_user('some-uuid')

        assert_that(result, equal_to(set()))

    def test_that_the_session_is_closed(self):
        self.query.all.return_value = []

        self.dao.label_ids_for_user('some-uuid')

        self.session.close.assert_called_once_with()
