Skip to content

Commit 87c2848

Browse files
committed
✅ add tests for MySQLtoSQLite constructor with missing parameters and error handling
1 parent 6eb13d6 commit 87c2848

File tree

1 file changed

+51
-12
lines changed

1 file changed

+51
-12
lines changed

tests/unit/test_transporter.py

Lines changed: 51 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -757,47 +757,86 @@ def test_build_create_table_sql_appends_strict(self) -> None:
757757

758758
assert "STRICT;" in sql
759759

760-
def test_constructor_missing_mysql_database(self) -> None:
760+
def test_constructor_missing_mysql_database(
761+
self,
762+
sqlite_database: "os.PathLike[t.Any]",
763+
mysql_credentials: MySQLCredentials,
764+
) -> None:
761765
"""Test constructor raises ValueError if mysql_database is missing."""
762766
from mysql_to_sqlite3.transporter import MySQLtoSQLite
763767

764768
with pytest.raises(ValueError, match="Please provide a MySQL database"):
765-
MySQLtoSQLite(mysql_user="user", sqlite_file="file.db")
769+
MySQLtoSQLite(
770+
sqlite_file=sqlite_database,
771+
mysql_user=mysql_credentials.user,
772+
)
766773

767-
def test_constructor_missing_mysql_user(self) -> None:
774+
def test_constructor_missing_mysql_user(
775+
self,
776+
sqlite_database: "os.PathLike[t.Any]",
777+
mysql_credentials: MySQLCredentials,
778+
) -> None:
768779
"""Test constructor raises ValueError if mysql_user is missing."""
769780
from mysql_to_sqlite3.transporter import MySQLtoSQLite
770781

771782
with pytest.raises(ValueError, match="Please provide a MySQL user"):
772-
MySQLtoSQLite(mysql_database="db", sqlite_file="file.db")
783+
MySQLtoSQLite(
784+
mysql_database=mysql_credentials.database,
785+
sqlite_file=sqlite_database,
786+
)
773787

774-
def test_constructor_missing_sqlite_file(self) -> None:
788+
def test_constructor_missing_sqlite_file(
789+
self,
790+
sqlite_database: "os.PathLike[t.Any]",
791+
mysql_credentials: MySQLCredentials,
792+
) -> None:
775793
"""Test constructor raises ValueError if sqlite_file is missing."""
776794
from mysql_to_sqlite3.transporter import MySQLtoSQLite
777795

778796
with pytest.raises(ValueError, match="Please provide an SQLite file"):
779-
MySQLtoSQLite(mysql_database="db", mysql_user="user")
797+
MySQLtoSQLite(
798+
mysql_database=mysql_credentials.database,
799+
mysql_user=mysql_credentials.user,
800+
)
780801

781-
def test_constructor_mutually_exclusive_tables(self) -> None:
802+
def test_constructor_mutually_exclusive_tables(
803+
self,
804+
sqlite_database: "os.PathLike[t.Any]",
805+
mysql_credentials: MySQLCredentials,
806+
) -> None:
782807
"""Test constructor raises ValueError if both mysql_tables and exclude_mysql_tables are provided."""
783808
from mysql_to_sqlite3.transporter import MySQLtoSQLite
784809

785810
with pytest.raises(ValueError, match="mutually exclusive"):
786811
MySQLtoSQLite(
787-
mysql_database="db",
788-
mysql_user="user",
789-
sqlite_file="file.db",
812+
sqlite_file=sqlite_database,
813+
mysql_user=mysql_credentials.user,
814+
mysql_password=mysql_credentials.password,
815+
mysql_host=mysql_credentials.host,
816+
mysql_port=mysql_credentials.port,
817+
mysql_database=mysql_credentials.database,
790818
mysql_tables=["a"],
791819
exclude_mysql_tables=["b"],
792820
)
793821

794-
def test_constructor_without_tables_and_data(self) -> None:
822+
def test_constructor_without_tables_and_data(
823+
self,
824+
sqlite_database: "os.PathLike[t.Any]",
825+
mysql_credentials: MySQLCredentials,
826+
) -> None:
795827
"""Test constructor raises ValueError if both without_tables and without_data are True."""
796828
from mysql_to_sqlite3.transporter import MySQLtoSQLite
797829

798830
with pytest.raises(ValueError, match="Unable to continue without transferring data or creating tables!"):
799831
MySQLtoSQLite(
800-
mysql_database="db", mysql_user="user", sqlite_file="file.db", without_tables=True, without_data=True
832+
sqlite_file=sqlite_database,
833+
mysql_user=mysql_credentials.user,
834+
mysql_password=mysql_credentials.password,
835+
mysql_host=mysql_credentials.host,
836+
mysql_port=mysql_credentials.port,
837+
mysql_database=mysql_credentials.database,
838+
without_tables=True,
839+
without_data=True,
801840
)
802841

803842
def test_translate_default_from_mysql_to_sqlite_none(self) -> None:

0 commit comments

Comments
 (0)