コード例 #1
0
 def test_mysql_hook_test_bulk_dump(self):
     hook = MySqlHook('airflow_db')
     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")
コード例 #2
0
 def test_mysql_hook_test_bulk_dump(self, client):
     with MySqlContext(client):
         hook = MySqlHook('airflow_db')
         priv = hook.get_first("SELECT @@global.secure_file_priv")
         # Use random names to allow re-running
         if priv and priv[0]:
             # Confirm that no error occurs
             hook.bulk_dump(
                 "INFORMATION_SCHEMA.TABLES",
                 os.path.join(priv[0], "TABLES_{}-{}".format(client, uuid.uuid1())),
             )
         elif priv == ("",):
             hook.bulk_dump("INFORMATION_SCHEMA.TABLES", "TABLES_{}_{}".format(client, uuid.uuid1()))
         else:
             self.skipTest("Skip test_mysql_hook_test_bulk_load " "since file output is not permitted")
コード例 #3
0
    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

        hook = MySqlHook('airflow_db')
        table = "INFORMATION_SCHEMA.TABLES"
        tmp_file = "/path/to/output/file"
        hook.bulk_dump(table, tmp_file)

        from tests.test_utils.asserts import assert_equal_ignore_multiple_spaces
        assert mock_execute.call_count == 1
        query = """
            SELECT * INTO OUTFILE '{tmp_file}'
            FROM {table}
        """.format(tmp_file=tmp_file, table=table)
        assert_equal_ignore_multiple_spaces(self, mock_execute.call_args[0][0], query)