def test_create_table_server_lost_connection_error(self, sqlite_database, mysql_database, mysql_credentials, mocker, caplog): proc = MySQLtoSQLite( sqlite_file=sqlite_database, mysql_user=mysql_credentials.user, mysql_password=mysql_credentials.password, mysql_database=mysql_credentials.database, mysql_host=mysql_credentials.host, mysql_port=mysql_credentials.port, ) class FakeSQLiteCursor: def executescript(self, *args, **kwargs): raise mysql.connector.Error( msg= "Error Code: 2013. Lost connection to MySQL server during query", errno=errorcode.CR_SERVER_LOST, ) class FakeSQLiteConnector: def commit(self, *args, **kwargs): return True mysql_inspect = inspect(mysql_database.engine) mysql_tables = mysql_inspect.get_table_names() mocker.patch.object(proc, "_sqlite_cur", FakeSQLiteCursor()) mocker.patch.object(proc._mysql, "reconnect", return_value=True) mocker.patch.object(proc, "_sqlite", FakeSQLiteConnector()) caplog.set_level(logging.DEBUG) with pytest.raises(mysql.connector.Error): proc._create_table(choice(mysql_tables))
def test_create_table_unknown_mysql_connector_error( self, sqlite_database, mysql_database, mysql_credentials, mocker, caplog): proc = MySQLtoSQLite( sqlite_file=sqlite_database, mysql_user=mysql_credentials.user, mysql_password=mysql_credentials.password, mysql_database=mysql_credentials.database, mysql_host=mysql_credentials.host, mysql_port=mysql_credentials.port, ) class FakeSQLiteCursor: def executescript(self, statement): raise mysql.connector.Error( msg="Error Code: 2000. Unknown MySQL error", errno=errorcode.CR_UNKNOWN_ERROR, ) mysql_inspect = inspect(mysql_database.engine) mysql_tables = mysql_inspect.get_table_names() mocker.patch.object(proc, "_sqlite_cur", FakeSQLiteCursor()) caplog.set_level(logging.DEBUG) with pytest.raises(mysql.connector.Error): proc._create_table(choice(mysql_tables))
def test_create_table_sqlite3_error(self, sqlite_database, mysql_database, mysql_credentials, mocker, caplog): proc = MySQLtoSQLite( sqlite_file=sqlite_database, mysql_user=mysql_credentials.user, mysql_password=mysql_credentials.password, mysql_database=mysql_credentials.database, mysql_host=mysql_credentials.host, mysql_port=mysql_credentials.port, ) class FakeSQLiteCursor: def executescript(self, *args, **kwargs): raise sqlite3.Error("Unknown SQLite error") mysql_inspect = inspect(mysql_database.engine) mysql_tables = mysql_inspect.get_table_names() mocker.patch.object(proc, "_sqlite_cur", FakeSQLiteCursor()) caplog.set_level(logging.DEBUG) with pytest.raises(sqlite3.Error): proc._create_table(choice(mysql_tables))