Example #1
0
def test_get_redis_connection_with_password(mocked_class, example_host,
                                            default_port, example_password,
                                            default_db):
    """
    Purpose:
        Tests that redis_connectors.get_redis_connection() will call StrictRedis with a
        password if one is provided
    Args:
        mocked_class (Mocked Class): Mocked version of redis.StrictRedis
        example_host (Pytest Fixture (String)): example host for redis
        default_port (Pytest Fixture (Int)): default port for redis
        example_password (Pytest Fixture (String)): example password for redis
        default_db (Pytest Fixture (Int)): default db for redis
    Return:
        N/A
    """

    # Test Call
    redis_con = redis_connectors.get_redis_connection(
        example_host, password=example_password)

    # Assertions
    mocked_class.assert_called_with(host=example_host,
                                    port=default_port,
                                    password=example_password,
                                    db=default_db)
    mocked_class.assert_called_once()
Example #2
0
def test_get_redis_connection_no_host(mocked_class):
    """
    Purpose:
        Tests that redis_connectors.get_redis_connection() requires at least a host. It
        should throw a TypeError if not
    Args:
        mocked_class (Mocked Class): Mocked version of redis.StrictRedis
    Return:
        N/A
    """

    with pytest.raises(TypeError):
        redis_con = redis_connectors.get_redis_connection()
Example #3
0
def test_get_redis_connection_redis_down(example_host):
    """
    Purpose:
        Tests that redis_connectors.get_redis_connection() throws a ConnectionError exception
        when there is no service (not using mock here, really want to try and connect
        to something that isn't there)
    Args:
        example_host (Pytest Fixture (String)): example host for redis
    Return:
        N/A
    """

    with pytest.raises(ConnectionError):
        redis_con = redis_connectors.get_redis_connection(example_host)
Example #4
0
def test_get_redis_connection_only_host(mocked_class, example_host,
                                        default_port, default_password,
                                        default_db):
    """
    Purpose:
        Tests that redis_connectors.get_redis_connection() requires at least a host
    Args:
        mocked_class (Mocked Class): Mocked version of redis.StrictRedis
        example_host (Pytest Fixture (String)): example host for redis
        default_port (Pytest Fixture (Int)): default port for redis
        default_password (Pytest Fixture (String)): default password for redis
        default_db (Pytest Fixture (Int)): default db for redis
    Return:
        N/A
    """

    # Test Call
    redis_con = redis_connectors.get_redis_connection(example_host)

    # Assertions
    mocked_class.assert_called_with(host=example_host,
                                    port=default_port,
                                    db=default_db)
    mocked_class.assert_called_once()