Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tests): Ensure deterministic SELECT ordering for CSV upload tests #23856

Merged
merged 6 commits into from
Apr 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions tests/integration_tests/csv_upload_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_import_csv_enforced_schema(mock_event_logger):

with get_upload_db().get_sqla_engine_with_context() as engine:
data = engine.execute(
f"SELECT * from {ADMIN_SCHEMA_NAME}.{CSV_UPLOAD_TABLE_W_SCHEMA}"
f"SELECT * from {ADMIN_SCHEMA_NAME}.{CSV_UPLOAD_TABLE_W_SCHEMA} ORDER BY b"
).fetchall()
assert data == [("john", 1), ("paul", 2)]

Expand Down Expand Up @@ -385,12 +385,12 @@ def test_import_csv(mock_event_logger):
)
# 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}").fetchall()
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}").fetchall()
data = engine.execute(f"SELECT * from {CSV_UPLOAD_TABLE} ORDER BY c").fetchall()
assert data == [("john", 1, "x"), ("paul", 2, None)]

# cleanup
Expand All @@ -408,7 +408,7 @@ def test_import_csv(mock_event_logger):
# 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}").fetchall()
data = engine.execute(f"SELECT * from {CSV_UPLOAD_TABLE} ORDER BY b").fetchall()
assert data == [("john", 1), ("paul", 2)]

# cleanup
Expand Down Expand Up @@ -480,7 +480,9 @@ def test_import_excel(mock_event_logger):
)

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


Expand Down Expand Up @@ -544,7 +546,9 @@ def test_import_parquet(mock_event_logger):
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()
data = engine.execute(
f"SELECT * from {PARQUET_UPLOAD_TABLE} ORDER BY b"
).fetchall()
assert data == [("john", 1), ("paul", 2)]

# replace table with zip file
Expand All @@ -555,5 +559,7 @@ def test_import_parquet(mock_event_logger):
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 == [("max", 3), ("bob", 4), ("john", 1), ("paul", 2)]
data = engine.execute(
f"SELECT * from {PARQUET_UPLOAD_TABLE} ORDER BY b"
).fetchall()
assert data == [("john", 1), ("paul", 2), ("max", 3), ("bob", 4)]