Ejemplo n.º 1
0
 def test_create_operator_with_wrong_parameters(
     self,
     project_id,
     location,
     instance_name,
     database_type,
     use_proxy,
     use_ssl,
     sql,
     message,
     get_connection,
 ):
     uri = (
         "gcpcloudsql://*****:*****@127.0.0.1:3200/testdb?"
         "database_type={database_type}&"
         "project_id={project_id}&location={location}&instance={instance_name}&"
         "use_proxy={use_proxy}&use_ssl={use_ssl}".format(
             database_type=database_type,
             project_id=project_id,
             location=location,
             instance_name=instance_name,
             use_proxy=use_proxy,
             use_ssl=use_ssl,
         ))
     self._setup_connections(get_connection, uri)
     with pytest.raises(AirflowException) as ctx:
         op = CloudSQLExecuteQueryOperator(sql=sql, task_id='task_id')
         op.execute(None)
     err = ctx.value
     assert message in str(err)
Ejemplo n.º 2
0
 def test_create_operator_with_too_long_unix_socket_path(
         self, get_connections):
     uri = "gcpcloudsql://*****:*****@127.0.0.1:3200/testdb?database_type=postgres&" \
           "project_id=example-project&location=europe-west1&" \
           "instance=" \
           "test_db_with_long_name_a_bit_above" \
           "_the_limit_of_UNIX_socket_asdadadasadasd&" \
           "use_proxy=True&sql_proxy_use_tcp=False"
     self._setup_connections(get_connections, uri)
     operator = CloudSQLExecuteQueryOperator(sql=['SELECT * FROM TABLE'],
                                             task_id='task_id')
     with self.assertRaises(AirflowException) as cm:
         operator.execute(None)
     err = cm.exception
     self.assertIn("The UNIX socket path length cannot exceed", str(err))
Ejemplo n.º 3
0
    "public_postgres_tcp_ssl",
    "proxy_mysql_tcp",
    "proxy_mysql_socket",
    "public_mysql_tcp",
    "public_mysql_tcp_ssl",
    "public_mysql_tcp_ssl_no_project_id",
]

tasks = []


with models.DAG(
    dag_id='example_gcp_sql_query',
    schedule_interval='@once',
    start_date=datetime(2021, 1, 1),
    catchup=False,
    tags=['example'],
) as dag:
    prev_task = None

    for connection_name in connection_names:
        task = CloudSQLExecuteQueryOperator(
            gcp_cloudsql_conn_id=connection_name, task_id="example_gcp_sql_task_" + connection_name, sql=SQL
        )
        tasks.append(task)
        if prev_task:
            prev_task >> task
        prev_task = task

# [END howto_operator_cloudsql_query_operators]