Commits

Anonymous committed 487a4c7

added

  • Participants
  • Parent commits d6c604a

Comments (0)

Files changed (1)

File test/websocket_test.py

+from gevent.queue import Queue
+import pytest
+from mock import Mock, patch
+from araldo_websocket.endpoints import websocket_endpoint as sut
+
+
+@pytest.fixture
+def config():
+    return {
+        "host": "localhost",
+        "websocket_url": "ws://localhost:12345/testsocket/",
+        "trace": True
+    }
+
+
+@pytest.fixture
+def plugin_manager():
+    plugin_manager = Mock()
+    marshal_json = Mock()
+    plugin_manager.plugin_instances.return_value = {
+        "araldo.marshalling": {
+            "marshal-json": marshal_json
+        }
+    }
+    return plugin_manager
+
+
+@pytest.fixture
+def queue():
+    return Queue()
+
+
+@pytest.fixture
+def create_connection():
+    create_connection_mock = Mock()
+    ws_mock = Mock()
+    create_connection_mock.return_value = ws_mock
+    return create_connection_mock
+
+
+@pytest.fixture
+def inbound(plugin_manager, config, queue, create_connection):
+    with patch.object(sut, "create_connection", create_connection):
+        result = sut.InBound(
+            name="ws_1",
+            plugin_manager=plugin_manager,
+            config=config,
+            gevent_queue=queue)
+        assert create_connection.called
+        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_inbound_plugin_id(inbound):
+    assert inbound.plugin_id() == "inbound-websocketclient"
+
+
+def test_outbound_plugin_id(outbound):
+    assert outbound.plugin_id() == "outbound-websocketclient"