24 lines
712 B
Python
24 lines
712 B
Python
import io
|
|
|
|
import pandas as pd
|
|
|
|
from routes.export_routes import _sanitize_excel_dataframe
|
|
|
|
|
|
def test_excel_export_sanitizer_removes_openpyxl_illegal_control_chars():
|
|
df = pd.DataFrame({
|
|
"商品名稱": ["【Cetaphil 舒特膚官方】Baby舒緩潤膚乳400ml\x0b"],
|
|
"價格": [399],
|
|
})
|
|
|
|
cleaned = _sanitize_excel_dataframe(df)
|
|
|
|
assert cleaned.loc[0, "商品名稱"] == "【Cetaphil 舒特膚官方】Baby舒緩潤膚乳400ml"
|
|
assert cleaned.loc[0, "價格"] == 399
|
|
|
|
output = io.BytesIO()
|
|
with pd.ExcelWriter(output, engine="openpyxl") as writer:
|
|
cleaned.to_excel(writer, index=False, sheet_name="PChome覆核隊列")
|
|
|
|
assert output.getbuffer().nbytes > 0
|