MCPcopy
hub / github.com/apache/superset / test_import_excel

Function test_import_excel

tests/integration_tests/csv_upload_tests.py:339–376  ·  view source on GitHub ↗
(setup_csv_upload, create_excel_files)

Source from the content-addressed store, hash-verified

337
338@mock.patch("superset.db_engine_specs.hive.upload_to_s3", mock_upload_to_s3)
339def test_import_excel(setup_csv_upload, create_excel_files):
340 if utils.backend() == "hive":
341 pytest.skip("Hive doesn't excel upload.")
342
343 success_msg = (
344 f'Excel file "{EXCEL_FILENAME}" uploaded to table "{EXCEL_UPLOAD_TABLE}"'
345 )
346
347 # initial upload with fail mode
348 resp = upload_excel(EXCEL_FILENAME, EXCEL_UPLOAD_TABLE)
349 assert success_msg in resp
350
351 # upload again with fail mode; should fail
352 fail_msg = f'Unable to upload Excel file "{EXCEL_FILENAME}" to table "{EXCEL_UPLOAD_TABLE}"'
353 resp = upload_excel(EXCEL_FILENAME, EXCEL_UPLOAD_TABLE)
354 assert fail_msg in resp
355
356 if utils.backend() != "hive":
357 # upload again with append mode
358 resp = upload_excel(
359 EXCEL_FILENAME, EXCEL_UPLOAD_TABLE, extra={"if_exists": "append"}
360 )
361 assert success_msg in resp
362
363 # upload again with replace mode
364 resp = upload_excel(
365 EXCEL_FILENAME, EXCEL_UPLOAD_TABLE, extra={"if_exists": "replace"}
366 )
367 assert success_msg in resp
368
369 # make sure that john and empty string are replaced with None
370 data = (
371 get_upload_db()
372 .get_sqla_engine()
373 .execute(f"SELECT * from {EXCEL_UPLOAD_TABLE}")
374 .fetchall()
375 )
376 assert data == [(0, "john", 1), (1, "paul", 2)]
377
378
379@mock.patch("superset.db_engine_specs.hive.upload_to_s3", mock_upload_to_s3)

Callers

nothing calls this directly

Calls 5

upload_excelFunction · 0.85
get_upload_dbFunction · 0.85
backendMethod · 0.80
get_sqla_engineMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected