# -*- coding: utf-8 -*-

# Copyright (C) 2018 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, see <http://www.gnu.org/licenses/>

import unittest
from mock import Mock, patch

from xivo_agid.modules.user_set_line_context import _user_set_line_context


class TestUserSetLineContext(unittest.TestCase):

    def setUp(self):
        self._agi = Mock()
        self._cursor = Mock()
        self._args = Mock()

    @patch("xivo_agid.handlers.userfeatures.UserFeatures")
    def test_set_line_context(self, mock_userfeatures):
        self._agi.get_variable.side_effect = \
            lambda x: {'XIVO_DSTID': '1'}.get(x, '')

        mocked_line = Mock()
        mocked_line.context = 'default'

        with patch('xivo_agid.objects.Line') as line:
            line.return_value = mocked_line
            _user_set_line_context(self._agi, mock_userfeatures)
            self._agi.set_variable.assert_called_once_with('XIVO_LINE_CONTEXT', 'default')
