1. Bernhard Biskup
  2. araldo-redis

Commits

bb b...@gmx.de  committed 0849b89 Draft

conformance

  • Participants
  • Parent commits 55da61c
  • Branches default

Comments (0)

Files changed (5)

File Makefile

View file
 	(cd doc && make html)
 
 test-pytest-full:
-	py.test -n 4 --cov ${PACKAGE} --cov-report=html test/
+	py.test --verbose --doctest-modules -n 4 --cov ${PACKAGE} --cov-report=html test/
 
 test-pytest-quick:
 	py.test --verbose --doctest-modules -n 4 test/ 

File araldo_redis/endpoints/redis.py

-
-""" araldo Endpoint for communication with Redis PubSub
-"""
-
-import logging
-from araldo.endpoints import EndPointBase
-
-
-class EndPoint(EndPointBase):
-    """ Endpoint for communication with Redis PubSub
-    """
-    def __init__(self):
-        self._logger = logging.getLogger("araldo_redis")
-        EndPointBase.__init__(self)
-
-    def name(self):
-        return "redis_pubsub"
-
-    def check(self):
-        """ implementation of abstract method
-        """
-        self._logger.debug("RedisEndPoint")

File araldo_redis/endpoints/redis_endpoint.py

View file
+
+""" araldo Endpoint for communication with Redis PubSub
+"""
+
+import logging
+from araldo.endpoints import EndPointBase, PluginException
+import redis
+
+
+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))

File setup.py

View file
     ],
     entry_points={
         "araldo.endpoints": [
-            "redis-endpoint = araldo_redis.endpoints.redis"
+            "redis-endpoint = araldo_redis.endpoints.redis_endpoint"
         ]
     },
     classifiers=[

File test/redis_test.py

View file
-from araldo_redis.endpoints.redis import EndPoint
+import pytest
+from mock import Mock
+from araldo_redis.endpoints.redis_endpoint import EndPoint
 
 
-def test_check():
-    end_point = EndPoint()
+@pytest.fixture
+def redis_mock():
+    result = Mock()
+    result.echo.side_effect = lambda x: x
+    return result
+
+
+@pytest.fixture
+def end_point(redis_mock):
+    def redis_server():
+        return redis_mock
+    return EndPoint(redis_server)
+
+
+def test_check(end_point):
     end_point.check()
+
+
+def test_name(end_point):
+    assert end_point.name() == "redis_pubsub"