Commits

Anonymous committed 6d57d21 Draft

new test cases

Comments (0)

Files changed (1)

test/router_test.py

 import pytest
+from mock import Mock
 import araldo.router as sut
 from araldo.config import Config
-from araldo.plugins import PluginManager
+from araldo import plugins
 
 
 @pytest.fixture
 
 
 @pytest.fixture
-def router(router_config, config):
-    PluginManager.create(config)
+def plugin_manager(config):
+    return plugins.PluginManager.create(config)
+
+
+@pytest.fixture
+def router(router_config, plugin_manager):
     return sut.Router(router_config)
 
 
 @pytest.fixture
 def test_instantiation(router):
-    assert router._routes == {"redis_1": ["redis_out_3"]}
+    assert router._routes == {"redis_1": ["redis_out_3", "redis_out_4"]}
+
+
+def test_existing_route(plugin_manager, router):
+    redis_out_3 = Mock()
+    outbound_entries = {"redis_out_3": redis_out_3}
+    router._outbound = outbound_entries
+    message = Mock()
+    router.route("redis_1", message)
+    assert redis_out_3.send.called
+
+
+def test_nonexisting_route(plugin_manager, router):
+    redis_out_3 = Mock()
+    outbound_entries = {"redis_out_3": redis_out_3}
+    router._outbound = outbound_entries
+    message = Mock()
+    router.route("redis_10", message)
+    assert not redis_out_3.send.called
+
+
+def test_recover_from_send_error(plugin_manager, router):
+    def raise_send(message):
+        raise Exception("test exception")
+
+    redis_out_3 = Mock()
+    redis_out_3.send.side_effect = raise_send
+    redis_out_4 = Mock()
+    outbound_entries = {
+        "redis_out_3": redis_out_3,
+        "redis_out_4": redis_out_4,
+    }
+    router._outbound = outbound_entries
+    message = Mock()
+    router.route("redis_1", message)
+    assert redis_out_3.send.called
+    assert redis_out_4.send.called