oncall-engine/engine/apps/slack/tests/test_create_message_blocks.py
Michael Derynck 6b40f95033 World, meet OnCall!
Co-authored-by: Eve832 <eve.meelan@grafana.com>
    Co-authored-by: Francisco Montes de Oca <nevermind89x@gmail.com>
    Co-authored-by: Ildar Iskhakov <ildar.iskhakov@grafana.com>
    Co-authored-by: Innokentii Konstantinov <innokenty.konstantinov@grafana.com>
    Co-authored-by: Julia <ferril.darkdiver@gmail.com>
    Co-authored-by: maskin25 <kengurek@gmail.com>
    Co-authored-by: Matias Bordese <mbordese@gmail.com>
    Co-authored-by: Matvey Kukuy <motakuk@gmail.com>
    Co-authored-by: Michael Derynck <michael.derynck@grafana.com>
    Co-authored-by: Richard Hartmann <richih@richih.org>
    Co-authored-by: Robby Milo <robbymilo@fastmail.com>
    Co-authored-by: Timur Olzhabayev <timur.olzhabayev@grafana.com>
    Co-authored-by: Vadim Stepanov <vadimkerr@gmail.com>
    Co-authored-by: Yulia Shanyrova <yulia.shanyrova@grafana.com>
2022-06-03 08:09:47 -06:00

56 lines
1.5 KiB
Python

from apps.slack.utils import create_message_blocks
def test_long_text():
original_text = "1" * 3000 + "\n" + "2" * 3000 + "\n" + "3" * 3000
message_block_dict = [
{
"type": "section",
"text": {"type": "mrkdwn", "text": "1" * 3000 + "```"},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```" + "2" * 3000 + "```",
},
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "```" + "3" * 3000 + "```",
},
},
]
assert message_block_dict == create_message_blocks(original_text)
def test_truncation_long_text():
original_text = "t" * 3000 + "\n" + "truncated"
expected_message_blocks = [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "t" * 3000 + "```",
},
},
{
"type": "section",
"text": {"type": "mrkdwn", "text": "```truncated```"},
},
]
message_blocks = create_message_blocks(original_text)
assert expected_message_blocks == message_blocks
def test_short_text():
"""Any short text test case"""
original_text = "test" * 100
message_block_dict = [{"type": "section", "text": {"type": "mrkdwn", "text": original_text}}]
assert message_block_dict == create_message_blocks(original_text)