-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Currently, we have some sql injection issues in our code which DeepSource detects for us, but some of them we ignored. ## What is the new behavior? This PR should fix them.
- Loading branch information
Showing
3 changed files
with
106 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
"""Tests all Database implementations.""" | ||
import pathlib | ||
|
||
import pandas as pd | ||
import pytest | ||
|
||
from astro.constants import Database | ||
from astro.files import File | ||
from astro.settings import SCHEMA | ||
from astro.sql.table import Metadata, Table | ||
|
||
CWD = pathlib.Path(__file__).parent | ||
|
||
|
||
@pytest.mark.integration | ||
@pytest.mark.parametrize( | ||
"database_table_fixture", | ||
[ | ||
{ | ||
"database": Database.BIGQUERY, | ||
"file": File(str(pathlib.Path(CWD.parent, "data/sample.csv"))), | ||
"table": Table(metadata=Metadata(schema=SCHEMA)), | ||
}, | ||
{ | ||
"database": Database.POSTGRES, | ||
"file": File(str(pathlib.Path(CWD.parent, "data/sample.csv"))), | ||
"table": Table(metadata=Metadata(schema=SCHEMA.lower())), | ||
}, | ||
{ | ||
"database": Database.REDSHIFT, | ||
"file": File(str(pathlib.Path(CWD.parent, "data/sample.csv"))), | ||
"table": Table(metadata=Metadata(schema=SCHEMA.lower())), | ||
}, | ||
{ | ||
"database": Database.SNOWFLAKE, | ||
"file": File(str(pathlib.Path(CWD.parent, "data/sample.csv"))), | ||
"table": Table(metadata=Metadata(schema=SCHEMA)), | ||
}, | ||
{ | ||
"database": Database.SQLITE, | ||
"file": File(str(pathlib.Path(CWD.parent, "data/sample.csv"))), | ||
"table": Table(), | ||
}, | ||
], | ||
indirect=True, | ||
ids=["bigquery", "postgres", "redshift", "snowflake", "sqlite"], | ||
) | ||
def test_export_table_to_pandas_dataframe( | ||
database_table_fixture, | ||
): | ||
"""Test export_table_to_pandas_dataframe() where the table exists""" | ||
database, table = database_table_fixture | ||
|
||
df = database.export_table_to_pandas_dataframe(table) | ||
assert len(df) == 3 | ||
expected = pd.DataFrame( | ||
[ | ||
{"id": 1, "name": "First"}, | ||
{"id": 2, "name": "Second"}, | ||
{"id": 3, "name": "Third with unicode पांचाल"}, | ||
] | ||
) | ||
assert df.rename(columns=str.lower).equals(expected) |