コード例 #1
0
def test_unload_gzipped(redshift):
    """Test gzip support."""
    setup_table_and_insert_data(redshift)

    redshift.execute(
        UNLOAD_TEMPLATE.format(
            COMMAND="UNLOAD",
            SELECT_STATEMENT="select * from test_s3_unload_from_redshift",
            TO="TO",
            LOCATION="s3://mybucket/myfile.csv.gz",
            AUTHORIZATION="AUTHORIZATION",
            OPTIONAL_ARGS="GZIP",
        )
    )

    fetch_values_from_s3_and_assert(redshift, file_name="myfile.csv.gz", is_gzipped=True)
コード例 #2
0
def test_unload_case_senesitivity(redshift):
    """Test case sensitivity for UNLOAD command."""
    setup_table_and_insert_data(redshift)

    redshift.execute(
        UNLOAD_TEMPLATE.format(
            COMMAND=randomcase("UNLOAD"),
            SELECT_STATEMENT="select * from test_s3_unload_from_redshift",
            TO=randomcase("TO"),
            LOCATION="s3://mybucket/myfile.csv",
            AUTHORIZATION=randomcase("AUTHORIZATION"),
            OPTIONAL_ARGS="",
        )
    )

    fetch_values_from_s3_and_assert(redshift, is_gzipped=False)
コード例 #3
0
def test_unload(redshift):
    """Test if a file is created with the appropriate data."""
    setup_table_and_insert_data(redshift)

    redshift.execute(
        UNLOAD_TEMPLATE.format(
            COMMAND="UNLOAD",
            SELECT_STATEMENT="select * from test_s3_unload_from_redshift",
            TO="TO",
            LOCATION="s3://mybucket/myfile.csv",
            AUTHORIZATION="AUTHORIZATION",
            OPTIONAL_ARGS="",
        )
    )

    fetch_values_from_s3_and_assert(redshift, is_gzipped=False)
コード例 #4
0
def test_random_spacing(redshift):
    """Test command with random spaces."""
    setup_table_and_insert_data(redshift)

    redshift.execute(
        UNLOAD_TEMPLATE.format(
            COMMAND="  UNLOAD           ",
            SELECT_STATEMENT="select * from test_s3_unload_from_redshift",
            TO="   TO          ",
            LOCATION="s3://mybucket/myfile.csv",
            AUTHORIZATION="   AUTHORIZATION         ",
            OPTIONAL_ARGS="   DELIMITER     AS      ','",
        )
    )

    fetch_values_from_s3_and_assert(redshift, is_gzipped=False, delimiter=",")
コード例 #5
0
def test_optional_keywords(redshift):
    """Test command with optimal keyword arguments."""
    with moto.mock_s3():
        setup_table_and_insert_data(redshift)

        redshift.execute(
            UNLOAD_TEMPLATE.format(
                COMMAND="UNLOAD",
                SELECT_STATEMENT="select * from test_s3_unload_from_redshift",
                TO="TO",
                LOCATION="s3://mybucket/myfile.csv",
                AUTHORIZATION="WITH AUTHORIZATION AS",
                OPTIONAL_ARGS="DELIMITER AS ','",
            )
        )

        fetch_values_from_s3_and_assert(redshift, is_gzipped=False, delimiter=",")
コード例 #6
0
def test_ignores_sqlalchmey_text_obj(redshift):
    """Test command ignores SQLAlchemy Text Objects and raises error."""
    setup_table_and_insert_data(redshift)
    try:
        redshift.execute(
            text(
                UNLOAD_TEMPLATE.format(
                    COMMAND=" UNLOAD",
                    SELECT_STATEMENT="select * from test_s3_unload_from_redshift",
                    TO="TO",
                    LOCATION="s3://mybucket/myfile.csv",
                    AUTHORIZATION="AUTHORIZATION",
                    OPTIONAL_ARGS="DELIMITER AS ','",
                )
            )
        )

    # The default engine will try to execute an `UNLOAD` command and will fail, raising a
    # ProgrammingError
    except sqlalchemy.exc.ProgrammingError:
        return