|
1 | 1 | import copy
|
2 | 2 | import unittest
|
3 |
| -from typing import Optional, List, Union |
| 3 | +from typing import List, Optional, Union |
4 | 4 |
|
5 | 5 | from slack_sdk.errors import SlackObjectFormationError
|
6 | 6 | from slack_sdk.models import JsonObject, JsonValidator
|
7 |
| -from slack_sdk.models.blocks import ( |
8 |
| - ConfirmObject, |
9 |
| - MarkdownTextObject, |
10 |
| - Option, |
11 |
| - OptionGroup, |
12 |
| - PlainTextObject, |
13 |
| -) |
14 |
| -from slack_sdk.models.blocks.basic_components import Workflow, WorkflowTrigger |
15 |
| -from slack_sdk.models.messages import ( |
16 |
| - ChannelLink, |
17 |
| - DateLink, |
18 |
| - EveryoneLink, |
19 |
| - HereLink, |
20 |
| - Link, |
21 |
| - ObjectLink, |
22 |
| -) |
23 |
| -from . import STRING_301_CHARS, STRING_51_CHARS |
| 7 | +from slack_sdk.models.blocks import ConfirmObject, MarkdownTextObject, Option, OptionGroup, PlainTextObject |
| 8 | +from slack_sdk.models.blocks.basic_components import FeedbackButtonObject, Workflow, WorkflowTrigger |
| 9 | +from slack_sdk.models.messages import ChannelLink, DateLink, EveryoneLink, HereLink, Link, ObjectLink |
| 10 | + |
| 11 | +from . import STRING_51_CHARS, STRING_301_CHARS |
24 | 12 |
|
25 | 13 |
|
26 | 14 | class SimpleJsonObject(JsonObject):
|
@@ -374,6 +362,55 @@ def test_deny_length(self):
|
374 | 362 | ConfirmObject(title="title", text="Are you sure?", deny=STRING_51_CHARS).to_dict()
|
375 | 363 |
|
376 | 364 |
|
| 365 | +class FeedbackButtonObjectTests(unittest.TestCase): |
| 366 | + def test_basic_json(self): |
| 367 | + feedback_button = FeedbackButtonObject(text="+1", value="positive") |
| 368 | + expected = {"text": {"type": "plain_text", "text": "+1", "emoji": True}, "value": "positive"} |
| 369 | + self.assertDictEqual(expected, feedback_button.to_dict()) |
| 370 | + |
| 371 | + def test_with_accessibility_label(self): |
| 372 | + feedback_button = FeedbackButtonObject(text="+1", value="positive", accessibility_label="Positive feedback button") |
| 373 | + expected = { |
| 374 | + "text": {"type": "plain_text", "text": "+1", "emoji": True}, |
| 375 | + "value": "positive", |
| 376 | + "accessibility_label": "Positive feedback button", |
| 377 | + } |
| 378 | + self.assertDictEqual(expected, feedback_button.to_dict()) |
| 379 | + |
| 380 | + def test_with_plain_text_object(self): |
| 381 | + text_obj = PlainTextObject(text="-1", emoji=False) |
| 382 | + feedback_button = FeedbackButtonObject(text=text_obj, value="negative") |
| 383 | + expected = {"text": {"type": "plain_text", "text": "-1", "emoji": False}, "value": "negative"} |
| 384 | + self.assertDictEqual(expected, feedback_button.to_dict()) |
| 385 | + |
| 386 | + def test_text_length_validation(self): |
| 387 | + with self.assertRaises(SlackObjectFormationError): |
| 388 | + FeedbackButtonObject(text="a" * 76, value="test").to_dict() |
| 389 | + |
| 390 | + def test_value_length_validation(self): |
| 391 | + with self.assertRaises(SlackObjectFormationError): |
| 392 | + FeedbackButtonObject(text="+1", value="a" * 2001).to_dict() |
| 393 | + |
| 394 | + def test_parse_from_dict(self): |
| 395 | + data = {"text": "+1", "value": "positive", "accessibility_label": "Positive feedback"} |
| 396 | + parsed = FeedbackButtonObject.parse(data) |
| 397 | + self.assertIsInstance(parsed, FeedbackButtonObject) |
| 398 | + expected = { |
| 399 | + "text": {"type": "plain_text", "text": "+1", "emoji": True}, |
| 400 | + "value": "positive", |
| 401 | + "accessibility_label": "Positive feedback", |
| 402 | + } |
| 403 | + self.assertDictEqual(expected, parsed.to_dict()) |
| 404 | + |
| 405 | + def test_parse_from_existing_object(self): |
| 406 | + original = FeedbackButtonObject(text="-1", value="negative") |
| 407 | + parsed = FeedbackButtonObject.parse(original) |
| 408 | + self.assertIs(original, parsed) |
| 409 | + |
| 410 | + def test_parse_none(self): |
| 411 | + self.assertIsNone(FeedbackButtonObject.parse(None)) |
| 412 | + |
| 413 | + |
377 | 414 | class OptionTests(unittest.TestCase):
|
378 | 415 | def setUp(self) -> None:
|
379 | 416 | self.common = Option(label="an option", value="option_1")
|
|
0 commit comments