# The software in this package is distributed under the GNU General # Public License version 2 (with a special exception described below). # # A copy of GNU General Public License (GPL) is included in this distribution, # in the file COPYING.GPL. # # As a special exception, if other files instantiate templates or use macros # or inline functions from this file, or you compile this file and link it # with other works to produce a work based on this file, this file # does not by itself cause the resulting work to be covered # by the GNU General Public License. # # However the source code for this file must still be made available # in accordance with section (3) of the GNU General Public License. # # This exception does not invalidate any other reasons why a work based # on this file might be covered by the GNU General Public License. # # Copyright (c) 2016-2022 Intra2net AG """ test_arnied_api.py: unit tests for arnied_api.py. Tests classes and functions in arnied_api.py For help see :py:mod:`unittest` """ import sys import unittest from unittest.mock import patch, Mock, ANY from src.arnied_api import Arnied, CnfVar, GetCnfQuery, GetCnfRet class ArniedTest(unittest.TestCase): """Test class Arnied.""" def setUp(self): """Set up the mocks.""" self._conn_mock = Mock() client_mock = Mock() client_mock.open = Mock(return_value=self._conn_mock) mod_mock = Mock() mod_mock.Client.new_with_address = Mock(return_value=client_mock) sys.modules["varlink"] = mod_mock def tearDown(self): """Clean up mocks.""" del sys.modules["varlink"] def test_simple_get_cnf_call(self): """Test that the get cnf method does some sanity checks.""" query = GetCnfQuery("USER", 5) cnfvar = CnfVar("USER", 5, "joe", deleted=False, children=[]) self._conn_mock.GetCnf = Mock(return_value=GetCnfRet(vars=[cnfvar])) retval = Arnied.get_cnf(query) self.assertEqual(retval.vars[0], cnfvar) if __name__ == '__main__': unittest.main()