mirror of
https://github.com/chatmail/relay.git
synced 2026-05-18 15:48:58 +00:00
introduce "mailboxes_dir" config ini option to avoid hardcoding /home/vmail/mail/....
in source code and to improve testability.
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
from chatmaild.delete_inactive_users import delete_inactive_users
|
||||
from chatmaild.doveauth import lookup_passdb
|
||||
@@ -8,9 +9,12 @@ def test_remove_stale_users(db, example_config):
|
||||
new = time.time()
|
||||
old = new - (example_config.delete_inactive_users_after * 86400) - 1
|
||||
|
||||
def get_user_path(addr):
|
||||
return Path(example_config.get_user_maildir(addr))
|
||||
|
||||
def create_user(addr, last_login):
|
||||
lookup_passdb(db, example_config, addr, "q9mr3faue", last_login=last_login)
|
||||
md = example_config.get_user_maildir(addr)
|
||||
md = get_user_path(addr)
|
||||
md.mkdir(parents=True)
|
||||
md.joinpath("cur").mkdir()
|
||||
md.joinpath("cur", "something").mkdir()
|
||||
@@ -33,19 +37,19 @@ def test_remove_stale_users(db, example_config):
|
||||
# check pre and post-conditions for delete_inactive_users()
|
||||
|
||||
for addr in to_remove:
|
||||
assert example_config.get_user_maildir(addr).exists()
|
||||
assert get_user_path(addr).exists()
|
||||
|
||||
delete_inactive_users(db, example_config)
|
||||
|
||||
for p in example_config.mail_basedir.iterdir():
|
||||
for p in Path(example_config.mailboxes_dir).iterdir():
|
||||
assert not p.name.startswith("old")
|
||||
|
||||
for addr in to_remove:
|
||||
assert not get_user_path(addr).exists()
|
||||
with db.read_connection() as conn:
|
||||
assert not conn.get_user(addr)
|
||||
assert not example_config.get_user_maildir(addr).exists()
|
||||
|
||||
for addr in remain:
|
||||
assert example_config.get_user_maildir(addr).exists()
|
||||
assert get_user_path(addr).exists()
|
||||
with db.read_connection() as conn:
|
||||
assert conn.get_user(addr)
|
||||
|
||||
Reference in New Issue
Block a user