test_admin_shortcuts.py 1.1 KB

123456789101112131415161718192021222324252627282930
  1. from __future__ import annotations
  2. import pytest
  3. @pytest.mark.parametrize(
  4. ("text", "expected"),
  5. [
  6. ("封禁", ("/ban", ["ban"])),
  7. ("解封", ("/unban", ["unban"])),
  8. ("禁言", ("/mute", ["mute"])),
  9. ("解除禁言", ("/unmute", ["unmute"])),
  10. ("警告", ("/warn", ["warn"])),
  11. ("禁言10分钟", ("/tmute 10m", ["tmute", "10m"])),
  12. ("禁言 2 小时", ("/tmute 2h", ["tmute", "2h"])),
  13. ("禁言1天", ("/tmute 1d", ["tmute", "1d"])),
  14. ("踢出", ("/kick", ["kick"])),
  15. ("踢", ("/kick", ["kick"])),
  16. ("飞", ("/kick", ["kick"])),
  17. ],
  18. )
  19. def test_member_action_shortcut_parser(app_modules, text, expected):
  20. shortcuts = app_modules.load("wbb.services.member_shortcuts")
  21. assert shortcuts.member_action_shortcut_command(text) == expected
  22. @pytest.mark.parametrize("text", ["禁言0分钟", "禁言100分钟", "封禁 原因", "踢他"])
  23. def test_member_action_shortcut_rejects_ambiguous_text(app_modules, text):
  24. shortcuts = app_modules.load("wbb.services.member_shortcuts")
  25. assert shortcuts.member_action_shortcut_command(text) is None