63 lines
1.7 KiB
Python
63 lines
1.7 KiB
Python
import unittest
|
|
from enum import Enum
|
|
|
|
from src.chat_identity import normalize_chat_kind_value, resolve_sender_name
|
|
|
|
|
|
class SampleChatType(str, Enum):
|
|
DIALOG = "DIALOG"
|
|
CHAT = "CHAT"
|
|
CHANNEL = "CHANNEL"
|
|
|
|
|
|
class ChatIdentityTests(unittest.TestCase):
|
|
def test_chat_kind_is_normalized(self) -> None:
|
|
cases = {
|
|
SampleChatType.DIALOG: "MaxDialog",
|
|
SampleChatType.CHAT: "Group",
|
|
SampleChatType.CHANNEL: "Channel",
|
|
"ChatType.CHAT": "Group",
|
|
"GROUP": "Group",
|
|
None: "MaxDialog",
|
|
}
|
|
for value, expected in cases.items():
|
|
with self.subTest(value=value):
|
|
self.assertEqual(expected, normalize_chat_kind_value(value))
|
|
|
|
def test_phone_book_name_has_priority(self) -> None:
|
|
self.assertEqual(
|
|
"Мама",
|
|
resolve_sender_name(
|
|
42,
|
|
is_outgoing=False,
|
|
phone_contact_names={"42": " Мама "},
|
|
profile_name="MAX Profile",
|
|
),
|
|
)
|
|
|
|
def test_profile_name_is_used_when_phone_name_is_missing(self) -> None:
|
|
self.assertEqual(
|
|
"MAX Profile",
|
|
resolve_sender_name(
|
|
42,
|
|
is_outgoing=False,
|
|
phone_contact_names={},
|
|
profile_name="MAX Profile",
|
|
),
|
|
)
|
|
|
|
def test_outgoing_message_uses_you(self) -> None:
|
|
self.assertEqual(
|
|
"You",
|
|
resolve_sender_name(
|
|
42,
|
|
is_outgoing=True,
|
|
phone_contact_names={"42": "Мама"},
|
|
profile_name="MAX Profile",
|
|
),
|
|
)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|