Commits

Anonymous committed 84d782e Draft

removed obsolete endpoint class; added check method; new TCs

Comments (0)

Files changed (2)

araldo_redis/endpoints/redis_endpoint.py

 from araldo.endpoints import InBoundBase, EndPointBase, PluginException
 
 
-class EndPoint(EndPointBase):
-    """ Endpoint for communication with Redis PubSub
-    """
-    def __init__(self, redis_server=None):
-        self._logger = logging.getLogger("araldo_redis")
-        EndPointBase.__init__(self)
-        if not redis_server:
-            redis_server = redis.Redis
-        self._redis = redis_server()
-
-    def name(self):
-        return "redis_pubsub"
-
-    def check(self):
-        """ implementation of abstract method
-        """
-        try:
-            response = self._redis.echo("x")
-            if response != "x":
-                raise PluginException("Redis echo failed")
-        except Exception as error:
-            raise PluginException("Redis connection problem: %s" % str(error))
 
 class InBound(InBoundBase):
     def __init__(self, config, gevent_queue, redis_server=None):
         """
         self._channel_name = config["channel"] 
         if not redis_server:
-            redis_server = redis.Redis
-        self._server = redis_server(
-            host=config["host"], 
-            port=config["port"])
+            self._server = redis.Redis(
+                host=config["host"], 
+                port=config["port"])
+        else:
+            self._server = redis_server
         self._client = self._server.pubsub()
         self._client.subscribe(self._channel_name)
         InBoundBase.__init__(self, config, gevent_queue)
             print "%s: received: %s" % (self, message)
             self.gevent_queue.put((self._channel_name, message))
             gevent.sleep(0)
-    
+
+
+    def check(self):
+        """ implementation of abstract method
+        """
+        try:
+            response = self._server.echo("x")
+            if response != "x":
+                raise PluginException("Redis echo failed")
+        except Exception as error:
+            raise PluginException("Redis connection problem: %s" % str(error))

test/redis_test.py

 from gevent import Timeout
 from mock import Mock
 from araldo.endpoints import PluginException
-from araldo_redis.endpoints.redis_endpoint import EndPoint, InBound
+from araldo_redis.endpoints.redis_endpoint import InBound
 
 
 @pytest.fixture
 
 
 @pytest.fixture
-def end_point(redis_mock):
-    return EndPoint(lambda: redis_mock)
-
-
-@pytest.fixture
 def config():
     return {
         "host": "localhost",
     return InBound(config, queue, redis_mock)
 
 
-def test_check(end_point):
-    end_point.check()
-
-
-def test_check_connection_problem():
+def test_check_connection_problem(config, queue):
     redis_mock = Mock()
 
     def f():
         raise redis.ConnectionError("test error")
     redis_mock.echo.side_effect = f
-    end_point = EndPoint(lambda: redis_mock)
+    end_point = InBound(config, queue, redis_mock)
     with pytest.raises(PluginException):
         end_point.check()
 
 
-def test_name(end_point):
-    assert end_point.name() == "redis_pubsub"
-
-
-def test_send(end_point):
-    end_point.send("testmessage")
-
-
 def test_inbound_run(inbound):
     timeout = Timeout(.1)
     timeout.start()
     with pytest.raises(Timeout):
         inbound.start()
         inbound.join()
+
+
+def test_check(inbound):
+    inbound.check()
+
+
+def test_plugin_id():
+    assert InBound.plugin_id() == "inbound-redis"