Skip to content

Commit a7f8f6d

Browse files
committed
Add Emoji class and integrate into tests and rendering
1 parent 8a56b25 commit a7f8f6d

4 files changed

Lines changed: 59 additions & 15 deletions

File tree

ca_slack_block_kit/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
from abc import ABC, abstractmethod
1212
from dataclasses import dataclass
1313

14+
from .emoji import Emoji # type: ignore[import]
15+
16+
__all__ = ["Emoji"]
17+
1418

1519
def render_blocks(blocks: list["Block"]) -> list[dict]:
1620
"""Render a list of Block objects into a list of dictionaries compatible with the Slack SDK client chat_postMessage function.

ca_slack_block_kit/emoji.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from dataclasses import dataclass
2+
3+
4+
@dataclass(frozen=True)
5+
class Emoji:
6+
"""Various emojis for easy use with Slack messages."""
7+
8+
THUMBS_UP = ":thumbsup:"
9+
THUMBS_DOWN = ":thumbsdown:"
10+
PARTY_POPPER = ":tada:"
11+
WARNING = ":warning:"
12+
CHECK_MARK = ":white_check_mark:"
13+
CROSS_MARK = ":x:"
14+
INFO = ":information_source:"
15+
ROCKET = ":rocket:"
16+
EYES = ":eyes:"
17+
FIRE = ":fire:"
18+
STAR = ":star:"
19+
HEART = ":heart:"
20+
CLAP = ":clap:"
21+
LIGHT_BULB = ":bulb:"
22+
HOURGLASS = ":hourglass_flowing_sand:"
23+
BUG = ":bug:"
24+
SPARKLES = ":sparkles:"

tests/integration_test.py

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
1-
from slack_sdk import WebClient
2-
from dotenv import load_dotenv
31
from os import environ
2+
3+
from dotenv import load_dotenv
4+
from slack_sdk import WebClient
5+
46
from ca_slack_block_kit import (
5-
Block,
7+
CodeBlock,
68
Divider,
9+
Emoji,
710
Header,
811
MarkdownSection,
9-
render_blocks,
1012
MarkdownSectionFields,
11-
CodeBlock,
13+
render_blocks,
1214
)
1315

1416
load_dotenv()
1517
client = WebClient(environ["SLACK_TOKEN"])
1618
TEST_CNANNEL_ID = "C07AGEKN0CB"
1719
TEST_MESSAGE_TITLE = "CA Stack Block Kit Integration Test"
18-
TEST_MARKDOWN_TEXT = """
20+
TEST_MARKDOWN_TEXT = f"""
1921
*This is a test markdown section*
2022
21-
- Bullet point 1 :smile:
22-
- Bullet point 2 :tada:
23-
- Bullet point 3 :rocket:
23+
- Bullet point 1 {Emoji.THUMBS_UP}
24+
- Bullet point 2 {Emoji.HEART}
25+
- Bullet point 3 {Emoji.ROCKET}
2426
2527
`Inline code`
2628
""".strip()
2729
TEST_MARKDOWN_FIELDS = [
28-
"*Field 1*: Value 1 :star:",
29-
"*Field 2*: Value 2 :heart:",
30-
"*Field 3*: Value 3 :fire:",
31-
"*Field 4*: Value 4 :thumbsup:",
30+
"*Field 1*: Value 1 " + Emoji.STAR,
31+
"*Field 2*: Value 2 " + Emoji.HEART,
32+
"*Field 3*: Value 3 " + Emoji.CLAP,
33+
"*Field 4*: Value 4 " + Emoji.BUG,
3234
]
3335
TEST_CODE_SNIPPET = """
3436
# This is a code snippet
@@ -37,7 +39,7 @@ def hello_world():
3739
""".strip()
3840

3941

40-
def test_message():
42+
def test_message() -> None:
4143
blocks = []
4244

4345
blocks.append(Header(text=TEST_MESSAGE_TITLE))

tests/unit_test.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
from ca_slack_block_kit import Divider
1+
from ca_slack_block_kit import Divider, Emoji
22

33

44
def test_divider_render() -> None:
55
divider = Divider()
66
expected_output = {"type": "divider"}
77
assert divider.render() == expected_output
8+
9+
10+
def test_emoji_constants() -> None:
11+
assert Emoji.THUMBS_UP == ":thumbsup:"
12+
assert Emoji.THUMBS_DOWN == ":thumbsdown:"
13+
assert Emoji.PARTY_POPPER == ":tada:"
14+
assert Emoji.WARNING == ":warning:"
15+
assert Emoji.CHECK_MARK == ":white_check_mark:"
16+
assert Emoji.CROSS_MARK == ":x:"
17+
assert Emoji.INFO == ":information_source:"
18+
assert Emoji.ROCKET == ":rocket:"
19+
assert Emoji.EYES == ":eyes:"
20+
assert Emoji.FIRE == ":fire:"
21+
assert Emoji.STAR == ":star:"

0 commit comments

Comments
 (0)