def test_with_connection_pool_config():
    with SettingsMock(
        SESSION_REDIS_CONNECTION_POOL='tests.tests.test_connection_pool'
    ):
        redis_server = get_redis_server()

        assert redis_server.connection_pool == test_connection_pool
def test_with_connection_pool_config():
    with SettingsMock(
        SESSION_REDIS_CONNECTION_POOL='tests.tests.test_connection_pool'
    ):
        redis_server = get_redis_server()

        assert redis_server.connection_pool == test_connection_pool
def test_redis_url_config():
    with SettingsMock(SESSION_REDIS_URL="redis://localhost:6379/1"):
        redis_server = get_redis_server()

        host = redis_server.connection_pool.connection_kwargs.get("host")
        port = redis_server.connection_pool.connection_kwargs.get("port")
        db = redis_server.connection_pool.connection_kwargs.get("db")

        assert host == "localhost"
        assert port == 6379
        assert db == 1
def test_redis_url_config():
    with SettingsMock(
        SESSION_REDIS_URL='redis://localhost:6379/1'
    ):
        redis_server = get_redis_server()

        host = redis_server.connection_pool.connection_kwargs.get('host')
        port = redis_server.connection_pool.connection_kwargs.get('port')
        db = redis_server.connection_pool.connection_kwargs.get('db')

        assert host == 'localhost'
        assert port == 6379
        assert db == 1
def test_redis_url_config():
    with SettingsMock(
        SESSION_REDIS_URL='redis://localhost:6379/1'
    ):
        redis_server = get_redis_server()

        host = redis_server.connection_pool.connection_kwargs.get('host')
        port = redis_server.connection_pool.connection_kwargs.get('port')
        db = redis_server.connection_pool.connection_kwargs.get('db')

        assert host == 'localhost'
        assert port == 6379
        assert db == 1
def test_unix_socket():
    # Uncomment this in `redis.conf`:
    #
    # unixsocket /tmp/redis.sock
    # unixsocketperm 755
    with SettingsMock(SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH="unix:///tmp/redis.sock"):
        redis_server = get_redis_server()

        path = redis_server.connection_pool.connection_kwargs.get("path")
        db = redis_server.connection_pool.connection_kwargs.get("db")

        assert path == settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH

        assert db == 0
def test_redis_url_config_from_env():
    os.environ["MYREDIS_URL"] = "redis://localhost:6379/2"

    _mock_session = SessionRedisConf()
    _mock_session.configure()

    with SettingsMock(SESSION_REDIS_URL=_mock_session.configured_data["URL"]):
        redis_server = get_redis_server()

        host = redis_server.connection_pool.connection_kwargs.get("host")
        port = redis_server.connection_pool.connection_kwargs.get("port")
        db = redis_server.connection_pool.connection_kwargs.get("db")

        assert host == "localhost"
        assert port == 6379
        assert db == 2
def test_redis_url_config_from_env():
    os.environ['MYREDIS_URL'] = 'redis://localhost:6379/2'

    _mock_session = SessionRedisConf()
    _mock_session.configure()

    with SettingsMock(SESSION_REDIS_URL=_mock_session.configured_data['URL']):
        redis_server = get_redis_server()

        host = redis_server.connection_pool.connection_kwargs.get('host')
        port = redis_server.connection_pool.connection_kwargs.get('port')
        db = redis_server.connection_pool.connection_kwargs.get('db')

        assert host == 'localhost'
        assert port == 6379
        assert db == 2
def test_unix_socket():
    # Uncomment this in `redis.conf`:
    #
    # unixsocket /tmp/redis.sock
    # unixsocketperm 755
    with SettingsMock(
        SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH='unix:///tmp/redis.sock'
    ):
        redis_server = get_redis_server()

        path = redis_server.connection_pool.connection_kwargs.get('path')
        db = redis_server.connection_pool.connection_kwargs.get('db')

        assert path == settings.SESSION_REDIS_UNIX_DOMAIN_SOCKET_PATH

        assert db == 0
def test_redis_url_config_from_env():
    os.environ['MYREDIS_URL'] = 'redis://localhost:6379/2'

    _mock_session = SessionRedisConf()
    _mock_session.configure()

    with SettingsMock(SESSION_REDIS_URL=_mock_session.configured_data['URL']):
        redis_server = get_redis_server()

        host = redis_server.connection_pool.connection_kwargs.get('host')
        port = redis_server.connection_pool.connection_kwargs.get('port')
        db = redis_server.connection_pool.connection_kwargs.get('db')

        assert host == 'localhost'
        assert port == 6379
        assert db == 2