コード例 #1
0
def unload_fn_to_test_psycopg2_connect_patch_as_context_manager(config):
    with psycopg2.connect(**config) as conn:
        with conn.cursor() as cursor:
            setup_table_and_insert_data(cursor)

            cursor.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(cursor, is_gzipped=False)
コード例 #2
0
def copy_fn_to_test_psycopg2_connect_patch_as_context_manager(config):
    with psycopg2.connect(**config) as conn:
        with conn.cursor() as cursor:
            setup_table_and_bucket(cursor)

            cursor.execute(
                COPY_TEMPLATE.format(
                    COMMAND="COPY",
                    LOCATION="s3://mybucket/file.csv",
                    COLUMNS="",
                    FROM="from",
                    CREDENTIALS="credentials",
                    OPTIONAL_ARGS="",
                )
            )

            fetch_and_assert_psycopg2(cursor)
コード例 #3
0
def copy_fn_to_test_psycopg2_connect_patch(config):
    with moto.mock_s3():
        conn = psycopg2.connect(**config)
        cursor = conn.cursor()
        setup_table_and_bucket(cursor)

        cursor.execute(
            COPY_TEMPLATE.format(
                COMMAND="COPY",
                LOCATION="s3://mybucket/file.csv",
                COLUMNS="(i, f, c, v)",
                FROM="from",
                CREDENTIALS="credentials",
                OPTIONAL_ARGS="EMPTYASNULL",
            )
        )

        fetch_and_assert_psycopg2(cursor)
コード例 #4
0
def mock_psycopg2_connect(*args, **kwargs):
    """Substitute the default cursor with a custom cursor."""
    conn = psycopg2.connect(*args, cursor_factory=CustomCursor, **kwargs)
    return conn