File tree Expand file tree Collapse file tree 5 files changed +61
-0
lines changed Expand file tree Collapse file tree 5 files changed +61
-0
lines changed Original file line number Diff line number Diff line change
1
+ MYSQL_USERNAME = root
2
+ MYSQL_PASSWORD = MySecretPassw0rd!
Original file line number Diff line number Diff line change
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}'
Original file line number Diff line number Diff line change @@ -36,6 +36,7 @@ def create_table_and_insert_data(database_url):
36
36
"postgresql+psycopg2://postgres:mysecretpassword@postgres_db:5432/postgres" ,
37
37
"mssql+pyodbc://sa:MySecretPassw0rd!@mssql_db:1433/master?driver=ODBC+Driver+17+for+SQL+Server" ,
38
38
"oracle+oracledb://system:MySecretPassw0rd!@oracle_db:1521/?service_name=XE" ,
39
+ "mysql+pymysql://root:MySecretPassw0rd!@mysql_db:3306/sys" ,
39
40
]
40
41
41
42
for url in DATABASE_URLS :
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments