示例#1
0
def test_warns_if_sql_scipt_does_not_create_relation():
    dag = DAG()

    t = SQLScript('SELECT * FROM {{product}}',
                  SQLiteRelation((None, 'my_table', 'table')),
                  dag=dag,
                  client=Mock(),
                  name='sql')

    match = 'will not create any tables or views but the task has product'

    with pytest.warns(UserWarning, match=match):
        t.render()
示例#2
0
def test_postgresscript_with_relation():
    dag = DAG()
    t = SQLScript('CREATE TABLE {{product}} AS SELECT * FROM {{name}}',
                  PostgresRelation(('user', 'table', 'table'), client=Dummy()),
                  dag,
                  name='name',
                  params=dict(name='some_table'),
                  client=Dummy())

    t.render()

    assert str(t.product) == 'user.table'
    assert (str(
        t.source) == 'CREATE TABLE user.table AS SELECT * FROM some_table')
示例#3
0
def test_warns_if_number_of_relations_does_not_match_products():
    dag = DAG()

    sql = """
    -- wrong sql, products must be used in CREATE statements
    CREATE TABLE {{product[0]}} AS
    SELECT * FROM my_table
    """

    t = SQLScript(sql, [
        SQLiteRelation((None, 'my_table', 'table')),
        SQLiteRelation((None, 'another_table', 'table'))
    ],
                  dag=dag,
                  client=Mock(),
                  name='sql')

    match = r'.*will create 1 relation\(s\) but you declared 2 product\(s\).*'

    with pytest.warns(UserWarning, match=match):
        t.render()
示例#4
0
def test_warns_if_sql_script_does_not_create_relation(
        sqlite_client_and_tmp_dir):
    client, _ = sqlite_client_and_tmp_dir
    dag = DAG()
    dag.clients[SQLiteRelation] = client

    mock_client = Mock()
    mock_client.split_source = ';'

    t = SQLScript('SELECT * FROM {{product}}',
                  SQLiteRelation((None, 'my_table', 'table')),
                  dag=dag,
                  client=mock_client,
                  name='sql')

    with pytest.warns(UserWarning) as record:
        t.render()

    assert len(record) == 1
    msg = ('It appears that your script will not create any tables/views but '
           "the product parameter is "
           "SQLiteRelation(('my_table', 'table'))")
    assert record[0].message.args[0] == msg