|
3 | 3 | from io import BytesIO |
4 | 4 | from pathlib import Path |
5 | 5 | from typing import Dict |
| 6 | +from unittest.mock import patch |
| 7 | + |
| 8 | +from slack_sdk.errors import SlackRequestError |
6 | 9 |
|
7 | 10 | from slack_sdk.models.attachments import Attachment |
8 | 11 | from slack_sdk.models.blocks import Block, DividerBlock |
@@ -147,6 +150,20 @@ def test_to_v2_file_upload_item_can_accept_file_as_path(self): |
147 | 150 | assert upload_item_path == upload_item_str |
148 | 151 | assert upload_item_str.get("filename") == "test_internal_utils.py" |
149 | 152 |
|
| 153 | + def test_to_v2_file_upload_item_raises_when_file_path_exceeds_1gb(self): |
| 154 | + with patch("os.path.getsize", return_value=1_073_741_825): |
| 155 | + with self.assertRaises(SlackRequestError) as ctx: |
| 156 | + _to_v2_file_upload_item({"file": "tests/slack_sdk/web/test_internal_utils.py"}) |
| 157 | + self.assertIn("Maximum upload file size is 1GB", str(ctx.exception)) |
| 158 | + self.assertIn("1073741825 bytes", str(ctx.exception)) |
| 159 | + |
| 160 | + def test_to_v2_file_upload_item_raises_when_content_exceeds_1gb(self): |
| 161 | + with patch("slack_sdk.web.internal_utils.MAX_V2_FILE_SIZE", 10): |
| 162 | + with self.assertRaises(SlackRequestError) as ctx: |
| 163 | + _to_v2_file_upload_item({"content": "this content is longer than 10 bytes", "filename": "test.txt"}) |
| 164 | + self.assertIn("Maximum upload file size is 1GB", str(ctx.exception)) |
| 165 | + self.assertIn("test.txt", str(ctx.exception)) |
| 166 | + |
150 | 167 | def test_next_cursor_is_present(self): |
151 | 168 | assert _next_cursor_is_present({"next_cursor": "next-page"}) is True |
152 | 169 | assert _next_cursor_is_present({"next_cursor": ""}) is False |
|
0 commit comments