|
1 | 1 | import unittest |
2 | 2 |
|
| 3 | +from slack_sdk.models.blocks import PlainTextObject, SectionBlock |
3 | 4 | from slack_sdk.models.blocks.block_elements import UrlSourceElement |
4 | | -from slack_sdk.models.messages.chunk import MarkdownTextChunk, PlanUpdateChunk, TaskUpdateChunk |
| 5 | +from slack_sdk.models.messages.chunk import BlocksChunk, Chunk, MarkdownTextChunk, PlanUpdateChunk, TaskUpdateChunk |
5 | 6 |
|
6 | 7 |
|
7 | 8 | class MarkdownTextChunkTests(unittest.TestCase): |
@@ -89,3 +90,46 @@ def test_json(self): |
89 | 90 | ], |
90 | 91 | }, |
91 | 92 | ) |
| 93 | + |
| 94 | + |
| 95 | +class BlocksChunkTests(unittest.TestCase): |
| 96 | + def test_json_with_dicts(self): |
| 97 | + self.assertDictEqual( |
| 98 | + BlocksChunk( |
| 99 | + blocks=[ |
| 100 | + {"type": "section", "text": {"type": "plain_text", "text": "Hello"}}, |
| 101 | + ] |
| 102 | + ).to_dict(), |
| 103 | + { |
| 104 | + "type": "blocks", |
| 105 | + "blocks": [ |
| 106 | + {"type": "section", "text": {"type": "plain_text", "text": "Hello"}}, |
| 107 | + ], |
| 108 | + }, |
| 109 | + ) |
| 110 | + |
| 111 | + def test_json_with_block_objects(self): |
| 112 | + self.assertDictEqual( |
| 113 | + BlocksChunk( |
| 114 | + blocks=[ |
| 115 | + SectionBlock(text=PlainTextObject(text="Hello")), |
| 116 | + ] |
| 117 | + ).to_dict(), |
| 118 | + { |
| 119 | + "type": "blocks", |
| 120 | + "blocks": [ |
| 121 | + {"type": "section", "text": {"type": "plain_text", "text": "Hello"}}, |
| 122 | + ], |
| 123 | + }, |
| 124 | + ) |
| 125 | + |
| 126 | + def test_parse(self): |
| 127 | + chunk = Chunk.parse( |
| 128 | + { |
| 129 | + "type": "blocks", |
| 130 | + "blocks": [{"type": "section", "text": {"type": "plain_text", "text": "Hello"}}], |
| 131 | + } |
| 132 | + ) |
| 133 | + self.assertIsInstance(chunk, BlocksChunk) |
| 134 | + self.assertEqual(chunk.type, "blocks") |
| 135 | + self.assertEqual(len(chunk.blocks), 1) |
0 commit comments