aboutsummaryrefslogtreecommitdiffstats
path: root/src/python/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/python/tests')
-rw-r--r--src/python/tests/__init__.py19
-rw-r--r--src/python/tests/mocs/__init__.py19
-rw-r--r--src/python/tests/mocs/mocked_session.py34
-rw-r--r--src/python/tests/netconf_server/__init__.py19
-rw-r--r--src/python/tests/netconf_server/sysrepo_configuration/__init__.py19
-rw-r--r--src/python/tests/netconf_server/sysrepo_configuration/test_sysrepo_configuration_loader.py84
-rw-r--r--src/python/tests/netconf_server/sysrepo_interface/__init__.py19
-rw-r--r--src/python/tests/netconf_server/sysrepo_interface/test_config_change_subscriber.py46
-rw-r--r--src/python/tests/netconf_server/test_netconf_server.py53
9 files changed, 312 insertions, 0 deletions
diff --git a/src/python/tests/__init__.py b/src/python/tests/__init__.py
new file mode 100644
index 0000000..eeb06d5
--- /dev/null
+++ b/src/python/tests/__init__.py
@@ -0,0 +1,19 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
diff --git a/src/python/tests/mocs/__init__.py b/src/python/tests/mocs/__init__.py
new file mode 100644
index 0000000..eeb06d5
--- /dev/null
+++ b/src/python/tests/mocs/__init__.py
@@ -0,0 +1,19 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
diff --git a/src/python/tests/mocs/mocked_session.py b/src/python/tests/mocs/mocked_session.py
new file mode 100644
index 0000000..d7adb1b
--- /dev/null
+++ b/src/python/tests/mocs/mocked_session.py
@@ -0,0 +1,34 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+import asyncio
+
+
+class MockedSession(object):
+
+ def __init__(self):
+ self.__callback = None
+
+ def subscribe_module_change(self, module_name, _, on_module_have_changed, asyncio_register=True):
+ self.__callback = on_module_have_changed
+ pass
+
+ def call_config_changed(self):
+ loop = asyncio.get_event_loop()
+ loop.run_until_complete(self.__callback('event', 'req_id', 'changes', 'private_data'))
diff --git a/src/python/tests/netconf_server/__init__.py b/src/python/tests/netconf_server/__init__.py
new file mode 100644
index 0000000..eeb06d5
--- /dev/null
+++ b/src/python/tests/netconf_server/__init__.py
@@ -0,0 +1,19 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
diff --git a/src/python/tests/netconf_server/sysrepo_configuration/__init__.py b/src/python/tests/netconf_server/sysrepo_configuration/__init__.py
new file mode 100644
index 0000000..eeb06d5
--- /dev/null
+++ b/src/python/tests/netconf_server/sysrepo_configuration/__init__.py
@@ -0,0 +1,19 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
diff --git a/src/python/tests/netconf_server/sysrepo_configuration/test_sysrepo_configuration_loader.py b/src/python/tests/netconf_server/sysrepo_configuration/test_sysrepo_configuration_loader.py
new file mode 100644
index 0000000..e5462e4
--- /dev/null
+++ b/src/python/tests/netconf_server/sysrepo_configuration/test_sysrepo_configuration_loader.py
@@ -0,0 +1,84 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+import unittest
+import os
+
+from netconf_server.sysrepo_configuration.sysrepo_configuration_loader import \
+ SysrepoConfigurationLoader, ConfigLoadingException
+
+test_config_file_name = "./test-subscription-configuration.ini"
+test_config_file_content = '[SUBSCRIPTION]\nmodels = test-module,test-module-2\n'
+
+test_wrong_config_file_name = "./test-subscription-wrong-configuration.ini"
+test_wrong_config_file_content = '[SUBSCRIPTION]\n'
+
+test_non_existing_config_file_name = "./test-subscription-non-existing-configuration.ini"
+
+
+class TestSysrepoConfigurationLoader(unittest.TestCase):
+
+ def test_should_load_configuration_from_file(self):
+ # when
+ config = SysrepoConfigurationLoader.load_configuration(test_config_file_name)
+
+ # then
+ self.assertEqual(config.models_to_subscribe_to, ["test-module", "test-module-2"])
+
+ def test_should_raise_exception_if_given_configuration_file_is_wrong(self):
+ # then
+ with self.assertRaises(ConfigLoadingException):
+ # when
+ SysrepoConfigurationLoader.load_configuration(test_wrong_config_file_name)
+
+ def test_should_raise_exception_if_given_configuration_file_does_not_exist(self):
+ # then
+ with self.assertRaises(ConfigLoadingException):
+ # when
+ SysrepoConfigurationLoader.load_configuration(test_non_existing_config_file_name)
+
+ @classmethod
+ def setUpClass(cls):
+ cls.__create_configuration_file()
+ cls.__create_wrong_configuration_file()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.__remove_configuration_files()
+ cls.__remove_wrong_configuration_files()
+
+ @staticmethod
+ def __create_configuration_file():
+ f = open(test_config_file_name, "a")
+ f.write(test_config_file_content)
+ f.close()
+
+ @staticmethod
+ def __remove_configuration_files():
+ os.remove(test_config_file_name)
+
+ @staticmethod
+ def __create_wrong_configuration_file():
+ f = open(test_wrong_config_file_name, "a")
+ f.write(test_wrong_config_file_content)
+ f.close()
+
+ @staticmethod
+ def __remove_wrong_configuration_files():
+ os.remove(test_wrong_config_file_name)
diff --git a/src/python/tests/netconf_server/sysrepo_interface/__init__.py b/src/python/tests/netconf_server/sysrepo_interface/__init__.py
new file mode 100644
index 0000000..eeb06d5
--- /dev/null
+++ b/src/python/tests/netconf_server/sysrepo_interface/__init__.py
@@ -0,0 +1,19 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
diff --git a/src/python/tests/netconf_server/sysrepo_interface/test_config_change_subscriber.py b/src/python/tests/netconf_server/sysrepo_interface/test_config_change_subscriber.py
new file mode 100644
index 0000000..9817ba4
--- /dev/null
+++ b/src/python/tests/netconf_server/sysrepo_interface/test_config_change_subscriber.py
@@ -0,0 +1,46 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+import unittest
+from unittest.mock import MagicMock
+
+from netconf_server.sysrepo_interface.config_change_data import ConfigChangeData
+from netconf_server.sysrepo_interface.config_change_subscriber import ConfigChangeSubscriber
+from tests.mocs.mocked_session import MockedSession
+
+
+class TestConfigChangeSubscriber(unittest.TestCase):
+
+ @staticmethod
+ def __test_callback(config_change_data: ConfigChangeData):
+ pass
+
+ def test_should_create_subscriber_and_call_callback_when_session_detects_change(self):
+ # given
+ self.__test_callback = MagicMock()
+ subscriber = ConfigChangeSubscriber("test", self.__test_callback)
+ session = MockedSession()
+ subscriber.subscribe_on_model_change(session)
+ self.__test_callback.assert_not_called()
+
+ # when
+ session.call_config_changed()
+
+ # then
+ self.__test_callback.assert_called_once()
diff --git a/src/python/tests/netconf_server/test_netconf_server.py b/src/python/tests/netconf_server/test_netconf_server.py
new file mode 100644
index 0000000..6306dd9
--- /dev/null
+++ b/src/python/tests/netconf_server/test_netconf_server.py
@@ -0,0 +1,53 @@
+###
+# ============LICENSE_START=======================================================
+# Netconf Server
+# ================================================================================
+# Copyright (C) 2021 Nokia. All rights reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+import unittest
+from unittest.mock import MagicMock
+
+from netconf_server.netconf_server_factory import NetconfServerFactory
+from tests.mocs.mocked_session import MockedSession
+
+
+class TestNetconfServer(unittest.TestCase):
+
+ def test_should_create_and_run_netconf_server_with_one_model(self):
+ # given
+ modules_to_subscribe_names = ["test"]
+ server = NetconfServerFactory(modules_to_subscribe_names).create()
+ session = MockedSession()
+ session.subscribe_module_change = MagicMock()
+
+ # when
+ server.run(session)
+
+ # then
+ session.subscribe_module_change.assert_called_once()
+
+ def test_should_create_and_run_netconf_server_with_multiple_models(self):
+ # given
+ modules_to_subscribe_names = ["test", "test2", "test3"]
+ server = NetconfServerFactory(modules_to_subscribe_names).create()
+ session = MockedSession()
+ session.subscribe_module_change = MagicMock()
+
+ # when
+ server.run(session)
+
+ # then
+ self.assertEqual(session.subscribe_module_change.call_count, 3)