Commits

bb b...@gmx.de  committed df97f9e

unified in- and out-bound endpoints

  • Participants
  • Parent commits 81491f9

Comments (0)

Files changed (3)

File araldo_websocket/endpoints/websocket_endpoint.py

 from gevent import monkey
 monkey.patch_all()
 from websocket import create_connection, enableTrace
-from araldo.endpoints import InBoundBase, OutBoundBase
+from araldo.endpoints import EndPointBase
 
 
-class InBound(InBoundBase):  # pylint: disable-msg=R0904
-    """ InBound endpoint implementation for connecting to a WebSocket server
+class EndPoint(EndPointBase):  # pylint: disable-msg=R0904
+    """ EndPoint implementation for connecting to a WebSocket server
     """
     def __init__(self, **kwargs):
-        """ Creates an InBound instance for relaying messages received
+        """ Creates an endpoint instance for relaying messages received
             from a WebSocket server
             :param config: configuration object
             :param gevent_queue: queue for forwarding incoming messages
         do_trace = config["trace"]
         enableTrace(do_trace)
         self._websocket = create_connection(websocket_url)
-        InBoundBase.__init__(self, **kwargs)
+        EndPointBase.__init__(self, **kwargs)
 
     @staticmethod
     def plugin_id():
         """ :return: ID of plugin
         """
-        return "inbound-websocketclient"
+        return "endpoint-websocketclient"
 
     def _get_next_message(self):
         """ Receive a single message from the WebSocket server
         """
         raise NotImplementedError()
 
-
-class OutBound(OutBoundBase):
-    """ Outound implementation for sending messages to WebSocket server
-    """
-    def __init__(self, **kwargs):
-        config = kwargs["config"]
-        do_trace = config["trace"]
-        enableTrace(do_trace)
-        websocket_url = config["websocket_url"]
-        self._websocket = create_connection(websocket_url)
-        OutBoundBase.__init__(self, **kwargs)
-
-    @staticmethod
-    def plugin_id():
-        """ :return: ID of plugin
-        """
-        return "outbound-websocketclient"
-
     def send(self, message):
         message_str = self._marshalling.to_external_format(message)
         self._logger.debug("message_str: %s", message_str)
         "websocket-client >= 0.8.0"
     ],
     entry_points={
-        "araldo.endpoints.inbound": [
-            ("websocketclient-inbound "
-             "= araldo_websocket.endpoints.websocket_endpoint")
-        ],
-        "araldo.endpoints.outbound": [
-            ("websocketclient-outbound "
+        "araldo.endpoints.endpoint": [
+            ("websocketclient-endpoint "
              "= araldo_websocket.endpoints.websocket_endpoint")
         ]
     },

File test/websocket_test.py

 
 
 @pytest.fixture
-def inbound(plugin_manager, config, queue, create_connection):
+def endpoint(plugin_manager, config, queue, create_connection):
     with patch.object(sut, "create_connection", create_connection):
-        result = sut.InBound(
+        result = sut.EndPoint(
             name="ws_1",
             plugin_manager=plugin_manager,
             config=config,
         return result
 
 
-@pytest.fixture
-def outbound(plugin_manager, config, create_connection):
-    with patch.object(sut, "create_connection", create_connection):
-        result = sut.OutBound(
-            name="ws_1",
-            plugin_manager=plugin_manager,
-            config=config)
-        assert create_connection.called
-        return result
+def test_plugin_id(endpoint):
+    assert endpoint.plugin_id() == "endpoint-websocketclient"
 
 
-def test_inbound_plugin_id(inbound):
-    assert inbound.plugin_id() == "inbound-websocketclient"
-
-
-def test_outbound_plugin_id(outbound):
-    assert outbound.plugin_id() == "outbound-websocketclient"
-
-
-def test_get_next_message(inbound, queue):
+def test_get_next_message(endpoint, queue):
     recv_mock = Mock()
     recv_mock.return_value = "test_message"
-    with patch.object(inbound._websocket, "recv", recv_mock):
-        inbound._get_next_message()
+    with patch.object(endpoint._websocket, "recv", recv_mock):
+        endpoint._get_next_message()
         assert recv_mock.called
         assert queue.qsize() == 1
 
 
-def test_inbound_run_exception(inbound):
-    with patch.object(inbound, "_get_next_message") as gnm:
+def test_run_exception(endpoint):
+    with patch.object(endpoint, "_get_next_message") as gnm:
         def f():
             raise Exception("test_exception")
 
         # terminate test of endless loop using timeout
         with gevent.Timeout(.1, TooLong):
             try:
-                inbound._run()
+                endpoint._run()
             except TooLong:
                 pass
 
 
-def test_outbound_send(outbound):
+def test_send(endpoint):
     message = Message(
         origin="test_origin",
         destination="test_destination",
         payload="test_payload")
-    with patch.object(outbound, "_websocket") as ws:
-        outbound.send(message)
+    with patch.object(endpoint, "_websocket") as ws:
+        endpoint.send(message)
         assert ws.send.called