[Python] Mock return value of CURL called from within Postgres stored procedure

Discussão em 'Python' iniciado por Stack, Maio 19, 2025.

  1. Stack

    Stack Membro Participativo

    I have a Postgres stored procedure that uses API call made by CURL command from within itself to obtain CSV file from outer server:

    create procedure import_national_standards()
    language plpgsql
    as
    $$
    BEGIN
    SET LOCAL statement_timeout = '60s';

    DROP TABLE IF EXISTS tmp;

    CREATE TEMPORARY TABLE tmp (
    code text,
    description text,
    is_active text,
    oks_code text
    );

    COPY tmp (code, description, is_active, oks_code)
    FROM PROGRAM 'curl -L -m 10 --compressed https:// ........ 20220330.csv'
    WITH
    delimiter ';'
    csv
    header
    ;

    DO SOMETHING WITH DATA ....



    Is it possible somehow mock response received from aforementioned CURL command with simple CSV file made specially for testing and launch this mock as a pytest fixture? This stored procedure is called from airflow SQL operatior and must be tested from within arflow service as well.

    Continue reading...

Compartilhe esta Página