-
Notifications
You must be signed in to change notification settings - Fork 857
Expand file tree
/
Copy pathtest_chunks.py
More file actions
135 lines (124 loc) · 4.23 KB
/
Copy pathtest_chunks.py
File metadata and controls
135 lines (124 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import unittest
from slack_sdk.models.blocks import PlainTextObject, SectionBlock
from slack_sdk.models.blocks.block_elements import UrlSourceElement
from slack_sdk.models.messages.chunk import BlocksChunk, Chunk, MarkdownTextChunk, PlanUpdateChunk, TaskUpdateChunk
class MarkdownTextChunkTests(unittest.TestCase):
def test_json(self):
self.assertDictEqual(
MarkdownTextChunk(text="greetings!").to_dict(),
{
"type": "markdown_text",
"text": "greetings!",
},
)
class PlanUpdateChunkTests(unittest.TestCase):
def test_json(self):
self.assertDictEqual(
PlanUpdateChunk(title="Crunching numbers...").to_dict(),
{
"type": "plan_update",
"title": "Crunching numbers...",
},
)
class TaskUpdateChunkTests(unittest.TestCase):
def test_json(self):
self.assertDictEqual(
TaskUpdateChunk(id="001", title="Waiting...", status="pending").to_dict(),
{
"type": "task_update",
"id": "001",
"title": "Waiting...",
"status": "pending",
},
)
self.assertDictEqual(
TaskUpdateChunk(
id="002",
title="Wondering...",
status="in_progress",
details="- Gathering information...",
).to_dict(),
{
"type": "task_update",
"id": "002",
"title": "Wondering...",
"status": "in_progress",
"details": "- Gathering information...",
},
)
self.assertDictEqual(
TaskUpdateChunk(
id="003",
title="Answering...",
status="complete",
output="Found a solution",
sources=[
UrlSourceElement(
text="Discussion of Life's Questions",
url="https://www.answers.com",
),
UrlSourceElement(
text="The Free Encyclopedia",
url="https://wikipedia.org",
),
],
).to_dict(),
{
"type": "task_update",
"id": "003",
"title": "Answering...",
"status": "complete",
"output": "Found a solution",
"sources": [
{
"type": "url",
"text": "Discussion of Life's Questions",
"url": "https://www.answers.com",
},
{
"type": "url",
"text": "The Free Encyclopedia",
"url": "https://wikipedia.org",
},
],
},
)
class BlocksChunkTests(unittest.TestCase):
def test_json_with_dicts(self):
self.assertDictEqual(
BlocksChunk(
blocks=[
{"type": "section", "text": {"type": "plain_text", "text": "Hello"}},
]
).to_dict(),
{
"type": "blocks",
"blocks": [
{"type": "section", "text": {"type": "plain_text", "text": "Hello"}},
],
},
)
def test_json_with_block_objects(self):
self.assertDictEqual(
BlocksChunk(
blocks=[
SectionBlock(text=PlainTextObject(text="Hello")),
]
).to_dict(),
{
"type": "blocks",
"blocks": [
{"type": "section", "text": {"type": "plain_text", "text": "Hello"}},
],
},
)
def test_parse(self):
chunk = Chunk.parse(
{
"type": "blocks",
"blocks": [{"type": "section", "text": {"type": "plain_text", "text": "Hello"}}],
}
)
self.assertIsInstance(chunk, BlocksChunk)
self.assertEqual(chunk.type, "blocks")
self.assertEqual(len(chunk.blocks), 1)