def test_mysql_hook_test_bulk_dump(self): from airflow.hooks.mysql_hook import MySqlHook hook = MySqlHook('airflow_ci') priv = hook.get_first("SELECT @@global.secure_file_priv") if priv and priv[0]: # Confirm that no error occurs hook.bulk_dump("INFORMATION_SCHEMA.TABLES", os.path.join(priv[0], "TABLES")) else: self.skipTest("Skip test_mysql_hook_test_bulk_load " "since file output is not permitted")
def test_mysql_hook_test_bulk_dump_mock(self, mock_get_conn): mock_execute = mock.MagicMock() mock_get_conn.return_value.cursor.return_value.execute = mock_execute from airflow.hooks.mysql_hook import MySqlHook hook = MySqlHook('airflow_ci') table = "INFORMATION_SCHEMA.TABLES" tmp_file = "/path/to/output/file" hook.bulk_dump(table, tmp_file) from airflow.utils.tests import assertEqualIgnoreMultipleSpaces mock_execute.assert_called_once() query = """ SELECT * INTO OUTFILE '{tmp_file}' FROM {table} """.format(tmp_file=tmp_file, table=table) assertEqualIgnoreMultipleSpaces(self, mock_execute.call_args[0][0], query)
def data_dump(table, tmp_file, mysql_conn_id='default_mysql'): if os.path.exists(tmp_file): os.remove(tmp_file) mysql_hook = MySqlHook(mysql_conn_id=mysql_conn_id) mysql_hook.bulk_dump(table, tmp_file)