code: def test_import_csv(mock_event_logger):
      schema = utils.get_example_default_schema()
      full_table_name = (
          f"{schema}.{CSV_UPLOAD_TABLE}" if schema else CSV_UPLOAD_TABLE
      )
      success_msg_f1 = f"CSV file {escaped_double_quotes(CSV_FILENAME1)} uploaded to table {escaped_double_quotes(full_table_name)}"
  
      test_db = get_upload_db()
  
      # initial upload with fail mode
      resp = upload_csv(CSV_FILENAME1, CSV_UPLOAD_TABLE)
      assert success_msg_f1 in resp
  
      # upload again with fail mode; should fail
      fail_msg = f"Unable to upload CSV file {escaped_double_quotes(CSV_FILENAME1)} to table {escaped_double_quotes(CSV_UPLOAD_TABLE)}"
      resp = upload_csv(CSV_FILENAME1, CSV_UPLOAD_TABLE)
      assert fail_msg in resp
  
      if utils.backend() != "hive":
          # upload again with append mode
          resp = upload_csv(
              CSV_FILENAME1,
              CSV_UPLOAD_TABLE,
              extra={"if_exists": "append"},
          )
          assert success_msg_f1 in resp
          mock_event_logger.assert_called_with(
              action="successful_csv_upload",
              database=test_db.name,
              schema=schema,
              table=CSV_UPLOAD_TABLE,
          )
  
      # upload again with replace mode
      resp = upload_csv(
          CSV_FILENAME1,
          CSV_UPLOAD_TABLE,
          extra={"if_exists": "replace"},
      )
      assert success_msg_f1 in resp
  
      # try to append to table from file with different schema
      resp = upload_csv(
          CSV_FILENAME2, CSV_UPLOAD_TABLE, extra={"if_exists": "append"}
      )
      fail_msg_f2 = f"Unable to upload CSV file {escaped_double_quotes(CSV_FILENAME2)} to table {escaped_double_quotes(CSV_UPLOAD_TABLE)}"
      assert fail_msg_f2 in resp
  
      # replace table from file with different schema
      resp = upload_csv(
          CSV_FILENAME2,
          CSV_UPLOAD_TABLE,
          extra={"if_exists": "replace"},
      )
      success_msg_f2 = f"CSV file {escaped_double_quotes(CSV_FILENAME2)} uploaded to table {escaped_double_quotes(full_table_name)}"
      assert success_msg_f2 in resp
  
      table = SupersetTestCase.get_table(name=CSV_UPLOAD_TABLE)
      # make sure the new column name is reflected in the table metadata
      assert "d" in table.column_names
  
      # ensure user is assigned as an owner
      assert security_manager.find_user("admin") in table.owners
  
      # null values are set
      upload_csv(
          CSV_FILENAME2,
          CSV_UPLOAD_TABLE,
          extra={"null_values": '["", "john"]', "if_exists": "replace"},
      )
      # make sure that john and empty string are replaced with None
      with test_db.get_sqla_engine_with_context() as engine:
          data = engine.execute(
              f"SELECT * from {CSV_UPLOAD_TABLE} ORDER BY c"
          ).fetchall()
          assert data == [(None, 1, "x"), ("paul", 2, None)]
          # default null values
          upload_csv(
              CSV_FILENAME2,
              CSV_UPLOAD_TABLE,
              extra={"if_exists": "replace"},
          )
          # make sure that john and empty string are replaced with None
          data = engine.execute(
              f"SELECT * from {CSV_UPLOAD_TABLE} ORDER BY c"
          ).fetchall()
          assert data == [("john", 1, "x"), ("paul", 2, None)]
  
      # cleanup
      with get_upload_db().get_sqla_engine_with_context() as engine:
          engine.execute(f"DROP TABLE {full_table_name}")
  
      # with dtype
      upload_csv(
          CSV_FILENAME1,
          CSV_UPLOAD_TABLE,
          dtype='{"a": "string", "b": "float64"}',
      )
  
      # you can change the type to something compatible, like an object to string
      # or an int to a float
      # file upload should work as normal
      with test_db.get_sqla_engine_with_context() as engine:
          data = engine.execute(
              f"SELECT * from {CSV_UPLOAD_TABLE} ORDER BY b"
          ).fetchall()
          assert data == [("john", 1), ("paul", 2)]
  
      # cleanup
      with get_upload_db().get_sqla_engine_with_context() as engine:
          engine.execute(f"DROP TABLE {full_table_name}")
  
      # with dtype - wrong type
      resp = upload_csv(
          CSV_FILENAME1,
          CSV_UPLOAD_TABLE,
          dtype='{"a": "int"}',
      )
  
      # you cannot pass an incompatible dtype
      fail_msg = f"Unable to upload CSV file {escaped_double_quotes(CSV_FILENAME1)} to table {escaped_double_quotes(CSV_UPLOAD_TABLE)}"
      assert fail_msg in resp
  
imports: import json
  import logging
  import os
  import shutil
  from typing import Optional, Union
  from unittest import mock
  import pandas
  import pytest
  import superset.utils.database
  from superset.sql_parse import Table
  from tests.integration_tests.conftest import ADMIN_SCHEMA_NAME
  from superset import db
  from superset import security_manager
  from superset.models.core import Database
  from superset.utils import core
  from tests.integration_tests.test_app import app, login
  from tests.integration_tests.base_tests import get_resp, SupersetTestCase
label_desc: Use image node_id 16 for calling a global function with example usage: test_import_csv(mock_event_logger) without return types