Skip to content

Commit 711f945

Browse files
Add MySQL integration tests
1 parent b439c74 commit 711f945

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

requirements.txt

18 Bytes
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MYSQL_USERNAME=root
2+
MYSQL_PASSWORD=MySecretPassw0rd!
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
connections:
2+
Mysql:
3+
sqlalchemy_driver: 'mysql+pymysql'
4+
server: 'mysql_db:3306'
5+
odbc_driver: ''
6+
database: 'sys'
7+
username: '${MYSQL_USERNAME}'
8+
password: '${MYSQL_PASSWORD}'

tests/integration/setup/migration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def create_table_and_insert_data(database_url):
3636
"postgresql+psycopg2://postgres:mysecretpassword@postgres_db:5432/postgres",
3737
"mssql+pyodbc://sa:MySecretPassw0rd!@mssql_db:1433/master?driver=ODBC+Driver+17+for+SQL+Server",
3838
"oracle+oracledb://system:MySecretPassw0rd!@oracle_db:1521/?service_name=XE",
39+
"mysql+pymysql://root:MySecretPassw0rd!@mysql_db:3306/sys",
3940
]
4041

4142
for url in DATABASE_URLS:

tests/integration/test_mysql.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import os
2+
from pathlib import Path
3+
import pytest
4+
import pandas as pd
5+
import sqlconnect as sc
6+
7+
if not os.environ.get("RUNNING_IN_DOCKER"):
8+
pytest.skip(
9+
"Skipping integration tests in local environment", allow_module_level=True
10+
)
11+
12+
13+
@pytest.fixture(scope="function")
14+
def setup_env():
15+
"""Fixture to set up sqlconnect.env"""
16+
source_env = Path("tests/integration/inputs/mysql_sqlconnect.env")
17+
target_env = Path().home() / "sqlconnect.env"
18+
19+
target_env.write_text(source_env.read_text(encoding="utf-8"))
20+
21+
yield
22+
23+
if target_env.exists():
24+
target_env.unlink()
25+
26+
27+
@pytest.fixture(scope="function")
28+
def setup_connections():
29+
"""Fixture to set up sqlconnect.yaml"""
30+
source_env = Path("tests/integration/inputs/mysql_sqlconnect.yaml")
31+
target_env = Path().home() / "sqlconnect.yaml"
32+
33+
target_env.write_text(source_env.read_text(encoding="utf-8"))
34+
35+
yield
36+
37+
if target_env.exists():
38+
target_env.unlink()
39+
40+
41+
def test_sql_to_df_str_postgres(setup_env, setup_connections):
42+
conn = sc.Sqlconnector("Mysql")
43+
44+
df = conn.sql_to_df_str(
45+
"SELECT name FROM sys.employees WHERE position = 'Data Engineer'"
46+
)
47+
48+
expected = pd.DataFrame({"name": ["Jane Doe"]})
49+
50+
pd.testing.assert_frame_equal(df, expected)

0 commit comments

Comments
 (0)