def test_get_connection_arg_LogicAndNetwork_success(self):
        LogicAndNetworkTmp = ComponentConnectionLogicAndNetwork(
            "slicer1network", "original", "running", "LogicId", "NetworkId"
        )
        body = 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"
            ),
            patch(
                "org.o3project.odenos.remoteobject.manager.system."
                "component_connection_logic_and_network."
                "ComponentConnectionLogicAndNetwork.create_from_packed",
                return_value=ComponentConnectionLogicAndNetwork.create_from_packed(body),
            ),
            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, 0)
            self.assertEqual(m_LogicAndNetwork.call_count, 1)
            m_LogicAndNetwork.assert_any_call(body)
            self.assertNotEqual(self.result, None)
            self.assertEqual(self.result.packed_object(), body)
            self.assertEqual(m_log_error.call_count, 0)
    def test_get_connections_create_from_packed_error(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,
        }
        debug_log = "GET Connections 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",
                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.assertEqual(self.result, None)
            m_log_error.assert_called_once_with(debug_log)
            self.assertEqual(m_log_error.call_count, 1)
    def test_create_from_packed_state_none(self):
        self.value = {"id": "slicer2->network2",
                      "connection_type": "test",
                      "logic_id": "123456789",
                      "network_id": "987654321"}

        self.result =\
            ComponentConnectionLogicAndNetwork.create_from_packed(self.value)
        self.assertEqual(self.result._property[self.target.OBJECT_ID],
                         "slicer2->network2")
        self.assertEqual(self.result._property[self.target.OBJECT_TYPE],
                         "LogicAndNetwork")
        self.assertEqual(self.result._property[self.target.CONNECTION_TYPE],
                         "test")
        self.assertEqual(self.result._property[self.target.OBJECT_STATE],
                         "initializing")
        self.assertEqual(self.result._property[self.target.LOGIC_ID],
                         "123456789")
        self.assertEqual(self.result._property[self.target.NETWORK_ID],
                         "987654321")
    def get_connections(self):
        logging.debug("GET Connections")
        resp = self._get_object_to_remote_object(self.CONNECTIONS_PATH)
        if resp.is_error(Request.Method.GET):
            return None

        connections = {}
        try:
            for conn_id, connection in resp.body.items():
                if connection[ComponentConnection.OBJECT_TYPE] ==\
                   ComponentConnectionLogicAndNetwork.TYPE:
                    connections[conn_id] =\
                        ComponentConnectionLogicAndNetwork.create_from_packed(
                            connection)
                else:
                    connections[conn_id] =\
                        ComponentConnection.create_from_packed(connection)
        except KeyError, err:
            logging.error("GET Connections Invalid Response Message"
                          + " KeyError: " + str(err))
            return None
    def get_connection(self, conn_id):
        logging.debug("GET Connection ConnectionID:" + conn_id)
        path = self.CONNECTION_PATH % conn_id
        resp = self._get_object_to_remote_object(path)
        if resp.is_error(Request.Method.GET):
            return None

        connection = None
        try:
            if resp.body[ComponentConnection.OBJECT_TYPE] ==\
               ComponentConnectionLogicAndNetwork.TYPE:
                connection =\
                    ComponentConnectionLogicAndNetwork.create_from_packed(
                        resp.body)
            else:
                connection =\
                    ComponentConnection.create_from_packed(resp.body)
        except KeyError, err:
            logging.error("GET Connection Invalid Response Message"
                          + " KeyError: " + str(err))
            return None