mirror of
https://github.com/chatmail/relay.git
synced 2026-05-13 17:34:38 +00:00
- test_doveauth: invalid localpart chars rejected, concurrent same-account creation - test_expire: --mdir filtering uses msg.path correctly - test_metadata: TURN exception returns N\n, success returns credentials - test_turnserver: socket timeout, connection refused, happy path - test_dns: get_dkim_entry returns (None, None) on CalledProcessError - test_rshell: dovecot_recalc_quota handles empty/malformed output
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
from unittest.mock import patch
|
|
|
|
from cmdeploy.remote.rshell import dovecot_recalc_quota
|
|
|
|
|
|
def test_dovecot_recalc_quota_normal_output():
|
|
"""Normal doveadm output returns parsed dict."""
|
|
normal_output = (
|
|
"Quota name Type Value Limit %\n"
|
|
"User quota STORAGE 5 102400 0\n"
|
|
"User quota MESSAGE 2 - 0\n"
|
|
)
|
|
|
|
with patch("cmdeploy.remote.rshell.shell", return_value=normal_output):
|
|
result = dovecot_recalc_quota("user@example.org")
|
|
|
|
# shell is called twice (recalc + get), patch returns same for both
|
|
assert result == {"value": 5, "limit": 102400, "percent": 0}
|
|
|
|
|
|
def test_dovecot_recalc_quota_empty_output():
|
|
"""Empty doveadm output (trailing newline) must not IndexError."""
|
|
call_count = [0]
|
|
|
|
def mock_shell(cmd):
|
|
call_count[0] += 1
|
|
if "recalc" in cmd:
|
|
return ""
|
|
# quota get returns only empty lines
|
|
return "\n\n"
|
|
|
|
with patch("cmdeploy.remote.rshell.shell", side_effect=mock_shell):
|
|
result = dovecot_recalc_quota("user@example.org")
|
|
|
|
assert result is None
|
|
|
|
|
|
def test_dovecot_recalc_quota_malformed_output():
|
|
"""Malformed output with too few columns must not crash."""
|
|
call_count = [0]
|
|
|
|
def mock_shell(cmd):
|
|
call_count[0] += 1
|
|
if "recalc" in cmd:
|
|
return ""
|
|
# partial line, fewer than 6 parts
|
|
return "Quota name\nUser quota STORAGE\n"
|
|
|
|
with patch("cmdeploy.remote.rshell.shell", side_effect=mock_shell):
|
|
result = dovecot_recalc_quota("user@example.org")
|
|
|
|
assert result is None
|
|
|
|
|
|
def test_dovecot_recalc_quota_header_only():
|
|
"""Only header line, no data rows."""
|
|
call_count = [0]
|
|
|
|
def mock_shell(cmd):
|
|
call_count[0] += 1
|
|
if "recalc" in cmd:
|
|
return ""
|
|
return "Quota name Type Value Limit %\n"
|
|
|
|
with patch("cmdeploy.remote.rshell.shell", side_effect=mock_shell):
|
|
result = dovecot_recalc_quota("user@example.org")
|
|
|
|
assert result is None
|