1- import os
2- import sys
31import unittest
42from types import SimpleNamespace
53from unittest .mock import AsyncMock , MagicMock
64
7- sys .path .append (os .path .join (os .path .dirname (__file__ ), ".." ))
8-
95from src .handlers .group_handler import GroupHandler
106
117
@@ -16,25 +12,13 @@ def setUp(self):
1612 escape_markdown = lambda value : str (value )
1713 )
1814
19- def test_missing_domain_page_is_compact_and_actionable (self ):
20- text = self .handler ._build_missing_domain_text ()
21-
22- self .assertIn ("没有识别到域名" , text )
23- self .assertIn ("重新 @机器人" , text )
24- self .assertIn ("`example.com`" , text )
25- self .assertNotIn ("•" , text )
26- self .assertIn ("🧪 *输入示例*" , text )
27- self .assertIn ("💬" , text )
28- self .assertLessEqual (len (text .splitlines ()), 9 )
29-
3015 def test_cn_page_has_no_nested_bold_code (self ):
3116 text = self .handler ._build_cn_domain_text ("example.cn" )
3217
3318 self .assertIn ("*.cn 域名无需添加*" , text )
3419 self .assertIn ("`example.cn`" , text )
3520 self .assertNotIn ("*域名 `" , text )
3621
37-
3822class TestGroupHandlerResultPages (unittest .IsolatedAsyncioTestCase ):
3923 def _handler_for_result (self , result , * , is_admin = False ):
4024 handler = GroupHandler .__new__ (GroupHandler )
@@ -49,57 +33,6 @@ def _handler_for_result(self, result, *, is_admin=False):
4933 )
5034 return handler
5135
52- async def test_added_page_uses_commit_button_and_short_lines (self ):
53- handler = self ._handler_for_result (
54- {
55- "action" : "added" ,
56- "target_domain" : "example.com" ,
57- "rate_limit_remaining" : 49 ,
58- "commit_sha" : "abcdef123456" ,
59- "commit_url" : "https://github.com/example/repo/commit/abcdef123456" ,
60- }
61- )
62- processing = SimpleNamespace (edit_text = AsyncMock ())
63- message = SimpleNamespace (reply_text = AsyncMock (return_value = processing ))
64-
65- await handler ._process_domain_request (
66- message , "example.com" , "alice" , 42
67- )
68-
69- initial_text = message .reply_text .await_args .args [0 ]
70- self .assertIn ("将自动写入公开 GitHub" , initial_text )
71- self .assertIn ("⚠️ 群聊流程不会再次要求确认" , initial_text )
72- result_call = processing .edit_text .await_args
73- self .assertIn ("直连规则已添加" , result_call .args [0 ])
74- self .assertIn ("🧾 *已写入规则*" , result_call .args [0 ])
75- self .assertNotIn ("https://" , result_call .args [0 ])
76- button = result_call .kwargs ["reply_markup" ].inline_keyboard [0 ][0 ]
77- self .assertIn ("abcdef12" , button .text )
78- self .assertEqual (
79- button .url ,
80- "https://github.com/example/repo/commit/abcdef123456" ,
81- )
82-
83- async def test_rejected_page_uses_policy_status_and_admin_action (self ):
84- handler = self ._handler_for_result (
85- {
86- "action" : "rejected" ,
87- "message" : "IP 和 NS 均不符合条件" ,
88- },
89- is_admin = True ,
90- )
91- processing = SimpleNamespace (edit_text = AsyncMock ())
92- message = SimpleNamespace (reply_text = AsyncMock (return_value = processing ))
93-
94- await handler ._process_domain_request (
95- message , "example.com" , "alice" , 42
96- )
97-
98- result_call = processing .edit_text .await_args
99- self .assertTrue (result_call .args [0 ].startswith ("⛔" ))
100- button = result_call .kwargs ["reply_markup" ].inline_keyboard [0 ][0 ]
101- self .assertEqual (button .callback_data , "admin_force|token" )
102-
10336 async def test_error_detail_is_single_line_and_bounded (self ):
10437 handler = self ._handler_for_result (
10538 {
0 commit comments