import unittest from reply_session_policy import excluded_session_reason, visual_group_title_reason, APPLICATION_REASON, GROUP_REASON class SessionPolicyTests(unittest.TestCase): def test_exact_application_titles_include_spacing_variants(self): for name in ('企小码', '企小码会话管理', ' 企 小 码 会话管理 ', '企小碼會話管理', '\u200b企小码会话管理'): self.assertEqual(excluded_session_reason(name=name), APPLICATION_REASON) def test_structured_group_ids_are_skipped(self): for identity in ('R:12345', 'r:abc', 'group@chatroom'): self.assertEqual(excluded_session_reason(conv_id=identity), GROUP_REASON) def test_explicit_metadata_and_nested_db_event_are_supported(self): for data in ({'is_group':True}, {'isGroup':'true'}, {'is_group_chat':1}, {'kind':'group'}, {'chat_type':'group_chat'}, {'conversation_type':'群聊'}, {'database_event':{'conv_id':'R:fixture'}}): self.assertEqual(excluded_session_reason(metadata=data), GROUP_REASON) def test_false_string_and_single_chat_types_do_not_block_customers(self): for data in ({'is_group':False}, {'is_group':'false'}, {'isGroup':0}, {'chat_type':'single'}, {'conversation_type':1}): self.assertEqual(excluded_session_reason(name='客户群芳',conv_id='S:100_200',metadata=data), '') def test_message_text_and_other_people_names_are_not_filters(self): for name in ('张三', '群芳', '企小码客服小李', '客户咨询群消息'): self.assertEqual(excluded_session_reason(name=name,conv_id='M:123',metadata={ 'text':'企小码会话管理', 'content':'群聊', 'messages':[{'is_group':True}]}), '') def test_opened_title_has_additional_member_count(self): for title in ('项目讨论(12)', '项目讨论(12)', ' 项目讨论 ( 12 ) '): self.assertEqual(visual_group_title_reason(title,name='项目讨论'), GROUP_REASON) def test_explicit_member_units_identify_group_header(self): for title in ('沟通(12人)', '项目讨论(3位成员)'): self.assertEqual(visual_group_title_reason(title), GROUP_REASON) def test_customer_parentheses_and_personal_wechat_title_are_not_groups(self): for title,name in (('张三(2)','张三(2)'), ('客户(12)@微信','客户'), ('项目讨论(1)','项目讨论'), ('项目讨论(12)',''), ('项目讨论(12)','另一位客户')): self.assertEqual(visual_group_title_reason(title,name=name), '') def test_list_unread_count_or_word_group_is_insufficient(self): for title in ('群聊相关咨询', '客户 12', '成员通知', '项目讨论[12条]'): self.assertEqual(visual_group_title_reason(title,name='客户'), '')