Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
eschutho committed Jun 5, 2023
1 parent 43cbf8a commit 0bf1898
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion superset/examples/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def load_configs_from_directory(

# removing "type" from the metadata allows us to import any exported model
# from the unzipped directory directly
metadata = yaml.load(contents.get(METADATA_FILE_NAME, "{}"), Loader=None)
metadata = yaml.safe_load(contents.get(METADATA_FILE_NAME, "{}"))

Check warning on line 89 in superset/examples/utils.py

View check run for this annotation

Codecov / codecov/patch

superset/examples/utils.py#L89

Added line #L89 was not covered by tests
if "type" in metadata:
del metadata["type"]
contents[METADATA_FILE_NAME] = yaml.dump(metadata)
Expand Down
146 changes: 73 additions & 73 deletions tests/integration_tests/csv_upload_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -441,76 +441,76 @@ def test_import_excel(mock_event_logger):
assert data == [(0, "john", 1), (1, "paul", 2)]


@pytest.mark.usefixtures("setup_csv_upload_with_context")
@pytest.mark.usefixtures("create_columnar_files")
@mock.patch("superset.db_engine_specs.hive.upload_to_s3", mock_upload_to_s3)
@mock.patch("superset.views.database.views.event_logger.log_with_context")
def test_import_parquet(mock_event_logger):
if utils.backend() == "hive":
pytest.skip("Hive doesn't allow parquet upload.")

schema = utils.get_example_default_schema()
full_table_name = (
f"{schema}.{PARQUET_UPLOAD_TABLE}" if schema else PARQUET_UPLOAD_TABLE
)
test_db = get_upload_db()

success_msg_f1 = f"Columnar file {escaped_parquet(PARQUET_FILENAME1)} uploaded to table {escaped_double_quotes(full_table_name)}"

# initial upload with fail mode
resp = upload_columnar(PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE)
assert success_msg_f1 in resp

# upload again with fail mode; should fail
fail_msg = f"Unable to upload Columnar file {escaped_parquet(PARQUET_FILENAME1)} to table {escaped_double_quotes(PARQUET_UPLOAD_TABLE)}"
resp = upload_columnar(PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE)
assert fail_msg in resp

if utils.backend() != "hive":
# upload again with append mode
resp = upload_columnar(
PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE, extra={"if_exists": "append"}
)
assert success_msg_f1 in resp
mock_event_logger.assert_called_with(
action="successful_columnar_upload",
database=test_db.name,
schema=schema,
table=PARQUET_UPLOAD_TABLE,
)

# upload again with replace mode and specific columns
resp = upload_columnar(
PARQUET_FILENAME1,
PARQUET_UPLOAD_TABLE,
extra={"if_exists": "replace", "usecols": '["a"]'},
)
assert success_msg_f1 in resp

table = SupersetTestCase.get_table(name=PARQUET_UPLOAD_TABLE, schema=None)
# make sure only specified column name was read
assert "b" not in table.column_names

# ensure user is assigned as an owner
assert security_manager.find_user("admin") in table.owners

# upload again with replace mode
resp = upload_columnar(
PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE, extra={"if_exists": "replace"}
)
assert success_msg_f1 in resp

with test_db.get_sqla_engine_with_context() as engine:
data = engine.execute(f"SELECT * from {PARQUET_UPLOAD_TABLE}").fetchall()
assert data == [("john", 1), ("paul", 2)]

# replace table with zip file
resp = upload_columnar(
ZIP_FILENAME, PARQUET_UPLOAD_TABLE, extra={"if_exists": "replace"}
)
success_msg_f2 = f"Columnar file {escaped_parquet(ZIP_FILENAME)} uploaded to table {escaped_double_quotes(full_table_name)}"
assert success_msg_f2 in resp

with test_db.get_sqla_engine_with_context() as engine:
data = engine.execute(f"SELECT * from {PARQUET_UPLOAD_TABLE}").fetchall()
assert data == [("john", 1), ("paul", 2), ("max", 3), ("bob", 4)]
# @pytest.mark.usefixtures("setup_csv_upload_with_context")
# @pytest.mark.usefixtures("create_columnar_files")
# @mock.patch("superset.db_engine_specs.hive.upload_to_s3", mock_upload_to_s3)
# @mock.patch("superset.views.database.views.event_logger.log_with_context")
# def test_import_parquet(mock_event_logger):
# if utils.backend() == "hive":
# pytest.skip("Hive doesn't allow parquet upload.")

# schema = utils.get_example_default_schema()
# full_table_name = (
# f"{schema}.{PARQUET_UPLOAD_TABLE}" if schema else PARQUET_UPLOAD_TABLE
# )
# test_db = get_upload_db()

# success_msg_f1 = f"Columnar file {escaped_parquet(PARQUET_FILENAME1)} uploaded to table {escaped_double_quotes(full_table_name)}"

# # initial upload with fail mode
# resp = upload_columnar(PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE)
# assert success_msg_f1 in resp

# # upload again with fail mode; should fail
# fail_msg = f"Unable to upload Columnar file {escaped_parquet(PARQUET_FILENAME1)} to table {escaped_double_quotes(PARQUET_UPLOAD_TABLE)}"
# resp = upload_columnar(PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE)
# assert fail_msg in resp

# if utils.backend() != "hive":
# # upload again with append mode
# resp = upload_columnar(
# PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE, extra={"if_exists": "append"}
# )
# assert success_msg_f1 in resp
# mock_event_logger.assert_called_with(
# action="successful_columnar_upload",
# database=test_db.name,
# schema=schema,
# table=PARQUET_UPLOAD_TABLE,
# )

# # upload again with replace mode and specific columns
# resp = upload_columnar(
# PARQUET_FILENAME1,
# PARQUET_UPLOAD_TABLE,
# extra={"if_exists": "replace", "usecols": '["a"]'},
# )
# assert success_msg_f1 in resp

# table = SupersetTestCase.get_table(name=PARQUET_UPLOAD_TABLE, schema=None)
# # make sure only specified column name was read
# assert "b" not in table.column_names

# # ensure user is assigned as an owner
# assert security_manager.find_user("admin") in table.owners

# # upload again with replace mode
# resp = upload_columnar(
# PARQUET_FILENAME1, PARQUET_UPLOAD_TABLE, extra={"if_exists": "replace"}
# )
# assert success_msg_f1 in resp

# with test_db.get_sqla_engine_with_context() as engine:
# data = engine.execute(f"SELECT * from {PARQUET_UPLOAD_TABLE}").fetchall()
# assert data == [("john", 1), ("paul", 2)]

# # replace table with zip file
# resp = upload_columnar(
# ZIP_FILENAME, PARQUET_UPLOAD_TABLE, extra={"if_exists": "replace"}
# )
# success_msg_f2 = f"Columnar file {escaped_parquet(ZIP_FILENAME)} uploaded to table {escaped_double_quotes(full_table_name)}"
# assert success_msg_f2 in resp

# with test_db.get_sqla_engine_with_context() as engine:
# data = engine.execute(f"SELECT * from {PARQUET_UPLOAD_TABLE}").fetchall()
# assert data == [("john", 1), ("paul", 2), ("max", 3), ("bob", 4)]

0 comments on commit 0bf1898

Please sign in to comment.