Пример #1
0
    def test_get_connection_arg_ComponentConnectio_success(self):
        ComponentConnectioTmp = ComponentConnection("slicer1network",
                                                    "original",
                                                    "running")
        body = ComponentConnectioTmp.packed_object()
        with nested(
                patch('org.o3project.odenos.core.util.remote_object_interface.'
                      'RemoteObjectInterface._get_object_to_remote_object',
                      return_value=Response(Response.StatusCode.OK,
                                            body)),
                patch('org.o3project.odenos.remoteobject.manager.system.'
                      'component_connection.ComponentConnection.'
                      'create_from_packed',
                      return_value=ComponentConnection.create_from_packed(
                          body)),
                patch('org.o3project.odenos.remoteobject.manager.system.'
                      'component_connection_logic_and_network.'
                      'ComponentConnectionLogicAndNetwork.create_from_packed'),
                patch('logging.error'
                      )) as (m_get_object,
                             m_Connection,
                             m_LogicAndNetwork,
                             m_log_error):

                self.result = self.target.get_connection("slicer1network")
                self.assertEqual(m_get_object.call_count, 1)
                m_get_object.assert_any_call(SystemManagerInterface.
                                             CONNECTION_PATH %
                                             "slicer1network")
                self.assertEqual(m_Connection.call_count, 1)
                m_Connection.assert_any_call(body)
                self.assertEqual(m_LogicAndNetwork.call_count, 0)
                self.assertNotEqual(self.result, None)
                self.assertEqual(self.result.packed_object(), body)
                self.assertEqual(m_log_error.call_count, 0)
Пример #2
0
    def test_get_connection_arg_create_from_packed_NG(self):
        ComponentConnectioTmp = ComponentConnection("slicer1network", "original", "running")
        body = ComponentConnectioTmp.packed_object()
        debug_log = "GET Connection Invalid Response Message" + " KeyError: 1"

        with nested(
            patch(
                "org.o3project.odenos.core.util.remote_object_interface."
                "RemoteObjectInterface._get_object_to_remote_object",
                return_value=Response(Response.StatusCode.OK, body),
            ),
            patch(
                "org.o3project.odenos.remoteobject.manager.system."
                "component_connection.ComponentConnection."
                "create_from_packed",
                side_effect=KeyError(1),
            ),
            patch(
                "org.o3project.odenos.remoteobject.manager.system."
                "component_connection_logic_and_network."
                "ComponentConnectionLogicAndNetwork.create_from_packed"
            ),
            patch("logging.error"),
        ) as (m_get_object, m_Connection, m_LogicAndNetwork, m_log_error):

            self.result = self.target.get_connection("slicer1network")
            self.assertEqual(m_get_object.call_count, 1)
            m_get_object.assert_any_call(SystemManagerInterface.CONNECTION_PATH % "slicer1network")
            self.assertEqual(m_Connection.call_count, 1)
            m_Connection.assert_any_call(body)
            self.assertEqual(m_LogicAndNetwork.call_count, 0)
            self.assertEqual(self.result, None)
            self.assertEqual(m_log_error.call_count, 1)
            m_log_error.assert_called_once_with(debug_log)
Пример #3
0
    def test_get_connections_success(self):
        ComponentConnectioTmp = ComponentConnection("slicer1_network1",
                                                    "original",
                                                    "running")
        LogicAndNetworkTmp =\
            ComponentConnectionLogicAndNetwork("slicer1_network2",
                                               "original",
                                               "running",
                                               "LogicId",
                                               "NetworkId")
        ComponentConnectioTmp_packed_object =\
            ComponentConnectioTmp.packed_object()
        LogicAndNetworkTmp_packed_object =\
            LogicAndNetworkTmp.packed_object()
        body = {"slicer1network": ComponentConnectioTmp_packed_object,
                "slicer2network": LogicAndNetworkTmp_packed_object}
        with nested(
                patch('org.o3project.odenos.core.util.remote_object_interface.'
                      'RemoteObjectInterface._get_object_to_remote_object',
                      return_value=Response(Response.StatusCode.OK, body)),
                patch('org.o3project.odenos.remoteobject.manager.system.'
                      'component_connection.ComponentConnection.'
                      'create_from_packed',
                      return_value=ComponentConnection.create_from_packed(
                          ComponentConnectioTmp_packed_object)),
                patch('org.o3project.odenos.remoteobject.manager.system.'
                      'component_connection_logic_and_network.'
                      'ComponentConnectionLogicAndNetwork.create_from_packed',
                      return_value=ComponentConnectionLogicAndNetwork.
                      create_from_packed(LogicAndNetworkTmp_packed_object)),
                patch('logging.error'
                      )) as (m_get_object,
                             m_Connection,
                             m_LogicAndNetwork,
                             m_log_error):

                self.result = self.target.get_connections()
                self.assertEqual(m_get_object.call_count, 1)
                m_get_object.assert_any_call(SystemManagerInterface.
                                             CONNECTIONS_PATH)
                self.assertEqual(m_Connection.call_count, 1)
                m_Connection.assert_any_call(
                    ComponentConnectioTmp_packed_object)
                self.assertEqual(m_LogicAndNetwork.call_count, 1)
                m_LogicAndNetwork.assert_any_call(
                    LogicAndNetworkTmp_packed_object)
                self.assertNotEqual(self.result, None)
                self.assertEqual(len(self.result), 2)
                self.assertEqual(self.result["slicer1network"].packed_object(),
                                 ComponentConnectioTmp_packed_object)
                self.assertEqual(self.result["slicer2network"].packed_object(),
                                 LogicAndNetworkTmp_packed_object)
                self.assertEqual(m_log_error.call_count, 0)
Пример #4
0
    def test_get_connections_success(self):
        ComponentConnectioTmp = ComponentConnection("slicer1_network1", "original", "running")
        LogicAndNetworkTmp = ComponentConnectionLogicAndNetwork(
            "slicer1_network2", "original", "running", "LogicId", "NetworkId"
        )
        ComponentConnectioTmp_packed_object = ComponentConnectioTmp.packed_object()
        LogicAndNetworkTmp_packed_object = LogicAndNetworkTmp.packed_object()
        body = {
            "slicer1network": ComponentConnectioTmp_packed_object,
            "slicer2network": LogicAndNetworkTmp_packed_object,
        }
        with nested(
            patch(
                "org.o3project.odenos.core.util.remote_object_interface."
                "RemoteObjectInterface._get_object_to_remote_object",
                return_value=Response(Response.StatusCode.OK, body),
            ),
            patch(
                "org.o3project.odenos.remoteobject.manager.system."
                "component_connection.ComponentConnection."
                "create_from_packed",
                return_value=ComponentConnection.create_from_packed(ComponentConnectioTmp_packed_object),
            ),
            patch(
                "org.o3project.odenos.remoteobject.manager.system."
                "component_connection_logic_and_network."
                "ComponentConnectionLogicAndNetwork.create_from_packed",
                return_value=ComponentConnectionLogicAndNetwork.create_from_packed(LogicAndNetworkTmp_packed_object),
            ),
            patch("logging.error"),
        ) as (m_get_object, m_Connection, m_LogicAndNetwork, m_log_error):

            self.result = self.target.get_connections()
            self.assertEqual(m_get_object.call_count, 1)
            m_get_object.assert_any_call(SystemManagerInterface.CONNECTIONS_PATH)
            self.assertEqual(m_Connection.call_count, 1)
            m_Connection.assert_any_call(ComponentConnectioTmp_packed_object)
            self.assertEqual(m_LogicAndNetwork.call_count, 1)
            m_LogicAndNetwork.assert_any_call(LogicAndNetworkTmp_packed_object)
            self.assertNotEqual(self.result, None)
            self.assertEqual(len(self.result), 2)
            self.assertEqual(self.result["slicer1network"].packed_object(), ComponentConnectioTmp_packed_object)
            self.assertEqual(self.result["slicer2network"].packed_object(), LogicAndNetworkTmp_packed_object)
            self.assertEqual(m_log_error.call_count, 0)
class ComponentConnectionTest(unittest.TestCase):

    def setUp(self):
        self.target = ComponentConnection("slicer1->network1",
                                          "original",
                                          "running")

    def tearDown(self):
        self.target = None

    def test_constructor_state_running(self):
        self.assertEqual(self.target._property[self.target.OBJECT_ID],
                         "slicer1->network1")
        self.assertEqual(self.target._property[self.target.OBJECT_TYPE],
                         "ComponentConnection")
        self.assertEqual(self.target._property[self.target.CONNECTION_TYPE],
                         "original")
        self.assertEqual(self.target._property[self.target.OBJECT_STATE],
                         "running")

    def test_constructor_Not_state(self):
        self.target = ComponentConnection("slicer1->network1",
                                          "original",
                                          None)

        self.assertEqual(self.target._property[self.target.OBJECT_ID],
                         "slicer1->network1")
        self.assertEqual(self.target._property[self.target.OBJECT_TYPE],
                         "ComponentConnection")
        self.assertEqual(self.target._property[self.target.CONNECTION_TYPE],
                         "original")
        self.assertEqual(self.target._property[self.target.OBJECT_STATE],
                         "initializing")

    def test_id(self):
        self.assertEqual(self.target.id, "slicer1->network1")

    def test_type(self):
        self.assertEqual(self.target.type, "ComponentConnection")

    def test_connection_type(self):
        self.assertEqual(self.target.connection_type, "original")

    def test_state(self):
        self.assertEqual(self.target.state, "running")

    def test_state_setter(self):
        self.target.state = "finalizing"
        self.assertEqual(self.target._property[self.target.OBJECT_STATE],
                         "finalizing")

    def test_is_read_only_key_id(self):
        self.assertEqual(self.target._is_read_only_key("id"), True)

    def test_is_read_only_key_type(self):
        self.assertEqual(self.target._is_read_only_key("type"), True)

    def test_is_read_only_key_connection_type(self):
        self.assertEqual(
            self.target._is_read_only_key("connection_type"), True)

    def test_is_read_only_key_state(self):
        self.assertEqual(self.target._is_read_only_key("state"), False)

    def test_get_property_id(self):
        self.assertEqual(self.target.get_property("id"),
                         "slicer1->network1")

    def test_get_property_type(self):
        self.assertEqual(self.target.get_property("type"),
                         "ComponentConnection")

    def test_get_property_connection_type(self):
        self.assertEqual(self.target.get_property("connection_type"),
                         "original")

    def test_get_property_state(self):
        self.assertEqual(self.target.get_property("state"),
                         "running")

    def test_set_property_state(self):
        self.target.set_property("state", "error")
        self.assertEqual(self.target._property["state"],
                         "error")

    def test_set_property_read_only_key(self):
        self.target.set_property("id", "slicer1")
        self.assertEqual(self.target._property["id"],
                         "slicer1->network1")

    def test_set_property_Same_Old(self):
        self.target.set_property("state", "running")
        self.assertEqual(self.target._property["state"],
                         "running")

    def test_get_property_keys(self):
        self.assertEqual(self.target.get_property_keys(),
                         self.target._property.keys())

    def test_create_from_packed(self):
        self.value = {"id": "slicer1->network1",
                      "type": "ComponentConnection",
                      "connection_type": "original",
                      "state": "initializing"}

        self.result = ComponentConnection.create_from_packed(self.value)
        self.assertEqual(self.result._property[self.target.OBJECT_ID],
                         "slicer1->network1")
        self.assertEqual(self.result._property[self.target.OBJECT_TYPE],
                         "ComponentConnection")
        self.assertEqual(self.result._property[self.target.CONNECTION_TYPE],
                         "original")
        self.assertEqual(self.result._property[self.target.OBJECT_STATE],
                         "initializing")

    def test_create_from_packed_State_None(self):
        self.value = {"id": "slicer1->network1",
                      "type": "ComponentConnection",
                      "connection_type": "original"}

        self.result = ComponentConnection.create_from_packed(self.value)
        self.assertEqual(self.result._property[self.target.OBJECT_ID],
                         "slicer1->network1")
        self.assertEqual(self.result._property[self.target.OBJECT_TYPE],
                         "ComponentConnection")
        self.assertEqual(self.result._property[self.target.CONNECTION_TYPE],
                         "original")
        self.assertEqual(self.result._property[self.target.OBJECT_STATE],
                         "initializing")

    def test_packed_object(self):
        self.result = self.target.packed_object()

        self.assertEqual(self.result[self.target.OBJECT_ID],
                         "slicer1->network1")
        self.assertEqual(self.result[self.target.OBJECT_TYPE],
                         "ComponentConnection")
        self.assertEqual(self.result[self.target.CONNECTION_TYPE],
                         "original")
        self.assertEqual(self.result[self.target.OBJECT_STATE],
                         "running")