114 lines
3.8 KiB
Python
114 lines
3.8 KiB
Python
from session_bot.render import build_channel_text
|
|
|
|
|
|
def test_build_channel_text_includes_phrase() -> None:
|
|
config = {
|
|
"template_text": "{{hidden_link}}\nheader\n\n{{actors}}",
|
|
"hidden_link_url": "https://example.com/image.png",
|
|
"actors": [
|
|
{
|
|
"key": "astat",
|
|
"display_name": "ASTAT",
|
|
"display_html": "<b>ASTAT</b>",
|
|
"link": "https://t.me/example",
|
|
"pronouns": "he/him",
|
|
"meta_html": " he/him ",
|
|
"emoji": "🌟",
|
|
"default_status": "backstage",
|
|
"phrases": {"open": "принимает тейки"},
|
|
}
|
|
],
|
|
}
|
|
state = {"actors": {"astat": {"status": "open", "phrase": "готов к игре"}}}
|
|
|
|
text = build_channel_text(config, state)
|
|
|
|
assert text.startswith('<a href="https://example.com/image.png">')
|
|
assert '<a href="https://t.me/example"><b>ASTAT</b></a>' in text
|
|
assert "готов к игре" in text
|
|
|
|
|
|
def test_build_channel_text_supports_per_actor_placeholders() -> None:
|
|
config = {
|
|
"template_text": "HEAD\n\n{{actor:astat}}\n\nMID\n\n{{actor:mari}}\n\nTAIL",
|
|
"actors": [
|
|
{
|
|
"key": "astat",
|
|
"display_name": "ASTAT",
|
|
"display_html": "<b>ASTAT</b>",
|
|
"link": "https://t.me/astat",
|
|
"pronouns": "he/him",
|
|
"meta_html": " he/him ",
|
|
"emoji": "🌟",
|
|
"default_status": "backstage",
|
|
"phrases": {"backstage": "в закулисье."},
|
|
},
|
|
{
|
|
"key": "mari",
|
|
"display_name": "MARI",
|
|
"display_html": "<b>MARI</b>",
|
|
"link": "https://t.me/mari",
|
|
"pronouns": "she/her",
|
|
"meta_html": " she/her ",
|
|
"emoji": "🌟",
|
|
"default_status": "open",
|
|
"phrases": {"open": "исполняет роль."},
|
|
},
|
|
],
|
|
}
|
|
|
|
text = build_channel_text(config, {"actors": {}})
|
|
|
|
assert text.count("<b>ASTAT</b>") == 1
|
|
assert text.count("<b>MARI</b>") == 1
|
|
|
|
|
|
def test_build_channel_text_inlines_actor_fragment_without_duplication() -> None:
|
|
config = {
|
|
"template_text": (
|
|
'🌟 <a href="https://t.me/liebe"><b>LIEBE</b></a> she/her {{actor:liebe}}\n'
|
|
'🌟 <a href="https://t.me/victor"><b>VICTOR</b></a> tech bot'
|
|
),
|
|
"actors": [
|
|
{
|
|
"key": "liebe",
|
|
"display_name": "LIEBE",
|
|
"display_html": "<b>LIEBE</b>",
|
|
"link": "https://t.me/liebe",
|
|
"pronouns": "she/her",
|
|
"meta_html": " she/her ",
|
|
"emoji": "🌟",
|
|
"default_status": "backstage",
|
|
"phrases": {"backstage": "в закулисье."},
|
|
}
|
|
],
|
|
}
|
|
|
|
text = build_channel_text(config, {"actors": {}})
|
|
|
|
assert text.count("<b>LIEBE</b>") == 1
|
|
assert "she/her в закулисье." in text
|
|
|
|
|
|
def test_plain_links_are_converted_to_html() -> None:
|
|
config = {
|
|
"template_text": "rules (https://example.com)\n\n{{actors}}",
|
|
"actors": [
|
|
{
|
|
"key": "astat",
|
|
"display_name": "ASTAT",
|
|
"display_html": "<b>ASTAT</b>",
|
|
"link": "https://t.me/astat",
|
|
"pronouns": "he/him",
|
|
"meta_html": " he/him ",
|
|
"emoji": "🌟",
|
|
"default_status": "backstage",
|
|
"phrases": {"backstage": "в закулисье."},
|
|
}
|
|
],
|
|
}
|
|
|
|
text = build_channel_text(config, {"actors": {}})
|
|
|
|
assert '<a href="https://example.com">rules</a>' in text
|