innovark37 commented on code in PR #40885: URL: https://github.com/apache/superset/pull/40885#discussion_r3602680973
########## tests/unit_tests/utils/test_core.py: ########## @@ -70,6 +71,39 @@ } [email protected]( + ("name", "content_type"), + [ + ( + "report.xlsx", + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + ), + ("report.zip", "application/zip"), + ], +) +def test_build_email_attachment( + name: str, + content_type: str, +) -> None: + """Email attachments should expose the expected MIME type and filename.""" + attachment = build_email_attachment(name, b"attachment") + + assert attachment.get_content_type() == content_type + assert attachment.get_filename() == name + assert attachment.get_payload(decode=True) == b"attachment" + + +def test_build_email_attachment_encodes_text_payload() -> None: + """Text attachment bodies should be encoded to stable UTF-8 bytes.""" + attachment = build_email_attachment("report.csv", "город,value\nМосква,1") + + assert attachment.get_content_type() == "application/octet-stream" + assert attachment.get_filename() == "report.csv" + assert attachment.get_payload(decode=True) == "город,value\nМосква,1".encode( + "utf-8" + ) Review Comment: Thanks, agreed. I folded the new text-payload case into the existing `test_build_email_attachment` parametrization, covering bytes ASCII, bytes UTF-8, and str UTF-8 without a separate overlapping test. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
