From d1fe20c1e0fb390927a37b4b63a3bbd0cfa50ebc Mon Sep 17 00:00:00 2001 From: Cristian Matiut Date: Fri, 29 Mar 2024 13:14:59 +0200 Subject: [PATCH] Add tests for `coriolis.endpoint_resources.api` module --- coriolis/tests/endpoint_resources/__init__.py | 0 coriolis/tests/endpoint_resources/test_api.py | 93 +++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 coriolis/tests/endpoint_resources/__init__.py create mode 100644 coriolis/tests/endpoint_resources/test_api.py diff --git a/coriolis/tests/endpoint_resources/__init__.py b/coriolis/tests/endpoint_resources/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/coriolis/tests/endpoint_resources/test_api.py b/coriolis/tests/endpoint_resources/test_api.py new file mode 100644 index 000000000..2e7de10e2 --- /dev/null +++ b/coriolis/tests/endpoint_resources/test_api.py @@ -0,0 +1,93 @@ +# Copyright 2024 Cloudbase Solutions Srl +# All Rights Reserved. + +from unittest import mock + +from coriolis.endpoint_resources import api +from coriolis.tests import test_base + +ARGS = { + "ctxt": "mock_ctxt", + "endpoint_id": "mock_endpoint_id" +} + + +class EndpointResourcesAPITestCase(test_base.CoriolisBaseTestCase): + """Test suite for the Coriolis Endpoint Resources API.""" + + def setUp(self): + super(EndpointResourcesAPITestCase, self).setUp() + self.endpoint_resources_api = api.API() + self.endpoint_resources_api._rpc_client = mock.Mock() + + def test_get_endpoint_instances(self): + result = self.endpoint_resources_api.get_endpoint_instances( + **ARGS, + source_environment=mock.sentinel.source_environment, + marker=mock.sentinel.marker, + limit=mock.sentinel.limit, + instance_name_pattern=mock.sentinel.instance_name_pattern + ) + (self.endpoint_resources_api._rpc_client. + get_endpoint_instances.assert_called_once_with)( + *(ARGS.values()), + mock.sentinel.source_environment, + mock.sentinel.marker, + mock.sentinel.limit, + mock.sentinel.instance_name_pattern + ) + self.assertEqual( + (self.endpoint_resources_api._rpc_client. + get_endpoint_instances.return_value), + result + ) + + def test_get_endpoint_instance(self): + result = self.endpoint_resources_api.get_endpoint_instance( + **ARGS, + source_environment=mock.sentinel.source_environment, + instance_name=mock.sentinel.instance_name + ) + (self.endpoint_resources_api._rpc_client. + get_endpoint_instance.assert_called_once_with)( + *(ARGS.values()), + mock.sentinel.source_environment, + mock.sentinel.instance_name + ) + self.assertEqual( + (self.endpoint_resources_api._rpc_client. + get_endpoint_instance.return_value), + result + ) + + def test_get_endpoint_networks(self): + result = self.endpoint_resources_api.get_endpoint_networks( + **ARGS, + env=mock.sentinel.env + ) + (self.endpoint_resources_api._rpc_client. + get_endpoint_networks.assert_called_once_with)( + *(ARGS.values()), + mock.sentinel.env + ) + self.assertEqual( + (self.endpoint_resources_api._rpc_client. + get_endpoint_networks.return_value), + result + ) + + def test_get_endpoint_storage(self): + result = self.endpoint_resources_api.get_endpoint_storage( + **ARGS, + env=mock.sentinel.env + ) + (self.endpoint_resources_api._rpc_client. + get_endpoint_storage.assert_called_once_with)( + *(ARGS.values()), + mock.sentinel.env + ) + self.assertEqual( + (self.endpoint_resources_api._rpc_client. + get_endpoint_storage.return_value), + result + )