1 # The software in this package is distributed under the GNU General
2 # Public License version 2 (with a special exception described below).
4 # A copy of GNU General Public License (GPL) is included in this distribution,
5 # in the file COPYING.GPL.
7 # As a special exception, if other files instantiate templates or use macros
8 # or inline functions from this file, or you compile this file and link it
9 # with other works to produce a work based on this file, this file
10 # does not by itself cause the resulting work to be covered
11 # by the GNU General Public License.
13 # However the source code for this file must still be made available
14 # in accordance with section (3) of the GNU General Public License.
16 # This exception does not invalidate any other reasons why a work based
17 # on this file might be covered by the GNU General Public License.
19 # Copyright (c) 2016-2022 Intra2net AG <info@intra2net.com>
22 test_arnied_api.py: unit tests for arnied_api.py.
24 Tests classes and functions in arnied_api.py
26 For help see :py:mod:`unittest`
31 from unittest.mock import patch, Mock, ANY
33 from src.arnied_api import Arnied, CnfVar, GetCnfQuery, GetCnfRet
36 class ArniedTest(unittest.TestCase):
37 """Test class Arnied."""
40 """Set up the mocks."""
41 self._conn_mock = Mock()
44 client_mock.open = Mock(return_value=self._conn_mock)
47 mod_mock.Client.new_with_address = Mock(return_value=client_mock)
49 sys.modules["varlink"] = mod_mock
53 del sys.modules["varlink"]
55 def test_simple_get_cnf_call(self):
56 """Test that the get cnf method does some sanity checks."""
57 query = GetCnfQuery("USER", 5)
58 cnfvar = CnfVar("USER", 5, "joe", deleted=False, children=[])
60 self._conn_mock.GetCnf = Mock(return_value=GetCnfRet(vars=[cnfvar]))
61 retval = Arnied.get_cnf(query)
63 self.assertEqual(retval.vars[0], cnfvar)
66 if __name__ == '__main__':