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

Function test_import_csv

tests/integration_tests/csv_upload_tests.py:263–335  ·  view source on GitHub ↗
(setup_csv_upload, create_csv_files)

Source from the content-addressed store, hash-verified

261
262@mock.patch("superset.db_engine_specs.hive.upload_to_s3", mock_upload_to_s3)
263def test_import_csv(setup_csv_upload, create_csv_files):
264 success_msg_f1 = (
265 f'CSV file "{CSV_FILENAME1}" uploaded to table "{CSV_UPLOAD_TABLE}"'
266 )
267
268 # initial upload with fail mode
269 resp = upload_csv(CSV_FILENAME1, CSV_UPLOAD_TABLE)
270 assert success_msg_f1 in resp
271
272 # upload again with fail mode; should fail
273 fail_msg = (
274 f'Unable to upload CSV file "{CSV_FILENAME1}" to table "{CSV_UPLOAD_TABLE}"'
275 )
276 resp = upload_csv(CSV_FILENAME1, CSV_UPLOAD_TABLE)
277 assert fail_msg in resp
278
279 if utils.backend() != "hive":
280 # upload again with append mode
281 resp = upload_csv(
282 CSV_FILENAME1, CSV_UPLOAD_TABLE, extra={"if_exists": "append"}
283 )
284 assert success_msg_f1 in resp
285
286 # upload again with replace mode and specific columns
287 resp = upload_csv(
288 CSV_FILENAME1,
289 CSV_UPLOAD_TABLE,
290 extra={"if_exists": "replace", "usecols": '["a"]'},
291 )
292 assert success_msg_f1 in resp
293
294 # make sure only specified column name was read
295 table = SupersetTestCase.get_table(name=CSV_UPLOAD_TABLE)
296 assert "b" not in table.column_names
297
298 # upload again with replace mode
299 resp = upload_csv(CSV_FILENAME1, CSV_UPLOAD_TABLE, extra={"if_exists": "replace"})
300 assert success_msg_f1 in resp
301
302 # try to append to table from file with different schema
303 resp = upload_csv(CSV_FILENAME2, CSV_UPLOAD_TABLE, extra={"if_exists": "append"})
304 fail_msg_f2 = (
305 f'Unable to upload CSV file "{CSV_FILENAME2}" to table "{CSV_UPLOAD_TABLE}"'
306 )
307 assert fail_msg_f2 in resp
308
309 # replace table from file with different schema
310 resp = upload_csv(CSV_FILENAME2, CSV_UPLOAD_TABLE, extra={"if_exists": "replace"})
311 success_msg_f2 = (
312 f'CSV file "{CSV_FILENAME2}" uploaded to table "{CSV_UPLOAD_TABLE}"'
313 )
314 assert success_msg_f2 in resp
315
316 table = SupersetTestCase.get_table(name=CSV_UPLOAD_TABLE)
317 # make sure the new column name is reflected in the table metadata
318 assert "d" in table.column_names
319
320 # null values are set

Callers

nothing calls this directly

Calls 6

upload_csvFunction · 0.85
get_upload_dbFunction · 0.85
backendMethod · 0.80
get_sqla_engineMethod · 0.80
get_tableMethod · 0.45
executeMethod · 0.45

Tested by

no test coverage detected