03a951d66efc29dd1d4c9fad09018f52178ed42e
[pyi2ncommon] / test / test_arnied_api.py
1 # The software in this package is distributed under the GNU General
2 # Public License version 2 (with a special exception described below).
3 #
4 # A copy of GNU General Public License (GPL) is included in this distribution,
5 # in the file COPYING.GPL.
6 #
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.
12 #
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.
15 #
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.
18 #
19 # Copyright (c) 2016-2022 Intra2net AG <info@intra2net.com>
20
21 """
22 test_arnied_api.py: unit tests for arnied_api.py.
23
24 Tests classes and functions in arnied_api.py
25
26 For help see :py:mod:`unittest`
27 """
28
29 import sys
30 import unittest
31 from unittest.mock import patch, Mock, ANY
32
33 from src.arnied_api import Arnied, CnfVar, GetCnfQuery, GetCnfRet
34
35
36 class ArniedTest(unittest.TestCase):
37     """Test class Arnied."""
38
39     def setUp(self):
40         """Set up the mocks."""
41         self._conn_mock = Mock()
42
43         client_mock = Mock()
44         client_mock.open = Mock(return_value=self._conn_mock)
45
46         mod_mock = Mock()
47         mod_mock.Client.new_with_address = Mock(return_value=client_mock)
48
49         sys.modules["varlink"] = mod_mock
50
51     def tearDown(self):
52         """Clean up mocks."""
53         del sys.modules["varlink"]
54
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=[])
59
60         self._conn_mock.GetCnf = Mock(return_value=GetCnfRet(vars=[cnfvar]))
61         retval = Arnied.get_cnf(query)
62
63         self.assertEqual(retval.vars[0], cnfvar)
64
65
66 if __name__ == '__main__':
67     unittest.main()