Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{health.ERROR_CANNOT_CONNECT_REDIS: "Could not connect to " "redis: fake"},
),
("redis", {health.ERROR_REDIS_EXCEPTION: 'Redis error: "fake"'}),
("malformed", {health.ERROR_REDIS_PING_FAILED: "Redis ping failed"}),
],
)
def test_redis_check_error(dockerflow_redis, mocker, test_client, error, messages):
assert "check_redis_connected" in dockerflow_redis.checks
fake_redis_error = functools.partial(fake_redis, error=error)
mocker.patch.object(sanic_redis.core, "create_redis_pool", fake_redis_error)
_, response = test_client.get("/__heartbeat__")
assert response.status == 500
assert response.json["status"] == "error"
assert response.json["details"]["check_redis_connected"]["messages"] == messages
(redis.ConnectionError, health.ERROR_CANNOT_CONNECT_REDIS),
(NotImplementedError, health.ERROR_MISSING_REDIS_CLIENT),
(ImproperlyConfigured, health.ERROR_MISCONFIGURED_REDIS),
],
)
def test_check_redis_connected(mocker, exception, error):
get_redis_connection = mocker.patch("django_redis.get_redis_connection")
get_redis_connection.side_effect = exception
errors = checks.check_redis_connected([])
assert len(errors) == 1
assert errors[0].id == error
(redis.ConnectionError, health.ERROR_CANNOT_CONNECT_REDIS),
(redis.RedisError, health.ERROR_REDIS_EXCEPTION),
],
)
def test_check_redis_connected(mocker, redis_store, exception, error):
ping = mocker.patch.object(redis_store, "ping")
ping.side_effect = exception
errors = checks.check_redis_connected(redis_store)
assert len(errors) == 1
assert errors[0].id == error