Exemple #1
0
def test_get_single_field():
    sql_query = 'select title from post;'

    parser = SQLParser(sql_query)
    actual = parser.get_fields()
    expected = ['title']

    assert actual == expected
Exemple #2
0
def test_get_multiple_fields_with_alias():

    sql_query = """SELECT child_entry,asdf AS inode, creation
              FROM links
              WHERE parent_dir == :parent_dir AND name == :name
              LIMIT 1"""

    parser = SQLParser(sql_query)
    actual = parser.get_fields()
    expected = ['child_entry', 'asdf', 'creation']

    assert set(actual) == set(expected)
Exemple #3
0
def test_get_multiple_fields_from_join_with_alias():
    sql_query = """SELECT e.last_name,
        e.department_id,
        d.department_name
        FROM   employees e
        LEFT OUTER JOIN department d
            ON ( e.department_id = d.department_id ); """

    parser = SQLParser(sql_query)
    actual = parser.get_fields()
    expected = ['last_name', 'department_id', 'department_name']

    assert set(actual) == set(expected)