|
1 | 1 | import json |
2 | 2 | import unittest |
| 3 | +from io import BytesIO |
3 | 4 | from typing import Dict, Sequence, Union |
4 | 5 |
|
5 | 6 | import pytest |
6 | 7 |
|
7 | 8 | from slack_sdk.models.attachments import Attachment |
8 | 9 | from slack_sdk.models.blocks import Block, DividerBlock |
9 | | -from slack_sdk.web.internal_utils import _build_unexpected_body_error_message, _parse_web_class_objects |
| 10 | +from slack_sdk.web.internal_utils import ( |
| 11 | + _build_unexpected_body_error_message, |
| 12 | + _parse_web_class_objects, |
| 13 | + _to_v2_file_upload_item, |
| 14 | +) |
10 | 15 |
|
11 | 16 |
|
12 | 17 | class TestInternalUtils(unittest.TestCase): |
@@ -72,3 +77,24 @@ def test_can_parse_user_auth_blocks(self): |
72 | 77 | } |
73 | 78 | _parse_web_class_objects(kwargs) |
74 | 79 | assert isinstance(kwargs["user_auth_blocks"][0], dict) |
| 80 | + |
| 81 | + def test_files_upload_v2_issue_1356(self): |
| 82 | + content_item = _to_v2_file_upload_item({"content": "test"}) |
| 83 | + assert content_item.get("filename") == "Uploaded file" |
| 84 | + |
| 85 | + filepath_item = _to_v2_file_upload_item({"file": "tests/slack_sdk/web/test_internal_utils.py"}) |
| 86 | + assert filepath_item.get("filename") == "test_internal_utils.py" |
| 87 | + filepath_item = _to_v2_file_upload_item({"file": "tests/slack_sdk/web/test_internal_utils.py", "filename": "foo.py"}) |
| 88 | + assert filepath_item.get("filename") == "foo.py" |
| 89 | + |
| 90 | + file_bytes = "This is a test!".encode("utf-8") |
| 91 | + file_bytes_item = _to_v2_file_upload_item({"file": file_bytes}) |
| 92 | + assert file_bytes_item.get("filename") == "Uploaded file" |
| 93 | + file_bytes_item = _to_v2_file_upload_item({"file": file_bytes, "filename": "foo.txt"}) |
| 94 | + assert file_bytes_item.get("filename") == "foo.txt" |
| 95 | + |
| 96 | + file_io = BytesIO(file_bytes) |
| 97 | + file_io_item = _to_v2_file_upload_item({"file": file_io}) |
| 98 | + assert file_io_item.get("filename") == "Uploaded file" |
| 99 | + file_io_item = _to_v2_file_upload_item({"file": file_io, "filename": "foo.txt"}) |
| 100 | + assert file_io_item.get("filename") == "foo.txt" |
0 commit comments