mirror of
https://github.com/chatmail/relay.git
synced 2026-05-17 01:48:58 +00:00
making it work
This commit is contained in:
@@ -2,87 +2,27 @@ from chatmaild.config import read_config
|
||||
import chatmaild.config
|
||||
|
||||
|
||||
def test_read_config_without_mailname(tmp_path, create_ini, monkeypatch):
|
||||
mailname_path = tmp_path.joinpath("mailname")
|
||||
mailname_path.write_text("something.example.org")
|
||||
monkeypatch.setattr(chatmaild.config, "system_mailname_path", mailname_path)
|
||||
def test_read_config_basic(make_config):
|
||||
config = make_config("chat.example.org")
|
||||
assert config.mailname == "chat.example.org"
|
||||
assert not config.privacy_supervisor and not config.privacy_mail
|
||||
assert not config.privacy_pdo and not config.privacy_postal
|
||||
|
||||
inipath = create_ini(
|
||||
"""
|
||||
[params]
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 9875
|
||||
postfix_reinject_port = 9999
|
||||
passthrough_recipients =
|
||||
"""
|
||||
)
|
||||
inipath = config._inipath
|
||||
inipath.write_text(inipath.read_text().replace("60", "37"))
|
||||
config = read_config(inipath)
|
||||
assert config.mailname == "something.example.org"
|
||||
assert config.max_user_send_per_minute == 37
|
||||
assert config.mailname == "chat.example.org"
|
||||
|
||||
|
||||
def test_read_config_without_privacy_policy(tmp_path, create_ini):
|
||||
inipath = create_ini(
|
||||
"""
|
||||
[params]
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 9875
|
||||
postfix_reinject_port = 9999
|
||||
passthrough_recipients =
|
||||
|
||||
[privacy:testrun]
|
||||
domain = *.example.org
|
||||
"""
|
||||
)
|
||||
config = read_config(inipath, "something.example.org")
|
||||
assert config.mailname == "something.example.org"
|
||||
assert config.max_user_send_per_minute == 40
|
||||
assert config.filtermail_smtp_port == 9875
|
||||
assert config.postfix_reinject_port == 9999
|
||||
assert config.passthrough_recipients == []
|
||||
assert not config.privacy_postal
|
||||
assert not config.privacy_mail
|
||||
assert not config.privacy_pdo
|
||||
assert not config.privacy_supervisor
|
||||
|
||||
|
||||
def test_read_config(create_ini):
|
||||
inipath = create_ini(
|
||||
"""
|
||||
[params]
|
||||
max_user_send_per_minute = 40
|
||||
filtermail_smtp_port = 10080
|
||||
postfix_reinject_port = 10025
|
||||
passthrough_recipients = x@example.org y@example.org
|
||||
|
||||
[privacy:testrun]
|
||||
domain = *.testrun.org
|
||||
|
||||
privacy_postal =
|
||||
Postal Ltd
|
||||
|
||||
privacy_mail = privacy@merlinux.eu
|
||||
|
||||
privacy_pdo =
|
||||
Postal PDO
|
||||
You can contact him at *delta-privacy@merlinux.eu* (Keyword: DPO)
|
||||
|
||||
privacy_supervisor =
|
||||
line1
|
||||
line2 with space
|
||||
"""
|
||||
)
|
||||
|
||||
config = read_config(inipath, "something.testrun.org")
|
||||
|
||||
def test_read_config_testrun(make_config):
|
||||
config = make_config("something.testrun.org")
|
||||
assert config.mailname == "something.testrun.org"
|
||||
assert len(config.privacy_postal.split("\n")) > 1
|
||||
assert len(config.privacy_supervisor.split("\n")) > 1
|
||||
assert len(config.privacy_pdo.split("\n")) > 1
|
||||
assert config.privacy_mail == "privacy@testrun.org"
|
||||
assert config.filtermail_smtp_port == 10080
|
||||
assert config.postfix_reinject_port == 10025
|
||||
assert config.passthrough_recipients == ["x@example.org", "y@example.org"]
|
||||
assert config.privacy_postal == "Postal Ltd"
|
||||
assert config.privacy_mail == "privacy@merlinux.eu"
|
||||
lines = config.privacy_pdo.split("\n")
|
||||
assert lines[0] == "Postal PDO"
|
||||
assert lines[1].startswith("You can ")
|
||||
lines = config.privacy_supervisor.split("\n")
|
||||
assert lines[0] == "line1"
|
||||
assert lines[1] == "line2 with space"
|
||||
assert config.max_user_send_per_minute == 60
|
||||
assert config.passthrough_recipients
|
||||
|
||||
@@ -39,13 +39,6 @@ def pytest_runtest_setup(item):
|
||||
pytest.skip("skipping slow test, use --slow to run")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def inipath():
|
||||
dpath = importlib.resources.files("chatmaild")
|
||||
inipath = dpath.joinpath("../../../chatmail.ini").resolve()
|
||||
assert inipath.exists()
|
||||
return inipath
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def maildomain():
|
||||
@@ -415,13 +408,13 @@ class CMUser:
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def create_ini(tmp_path, inipath):
|
||||
def create_ini_func(source=None):
|
||||
if source is None:
|
||||
source = inipath.read_text()
|
||||
p = tmp_path.joinpath("chatmail.ini")
|
||||
assert not p.exists(), p
|
||||
p.write_text(textwrap.dedent(source))
|
||||
return p
|
||||
def make_config(tmp_path):
|
||||
from deploy_chatmail.cmdeploy import main
|
||||
from chatmaild.config import read_config
|
||||
inipath = tmp_path.joinpath("chatmail.ini")
|
||||
|
||||
return create_ini_func
|
||||
def make_conf(mailname):
|
||||
main(["init", "--config", str(inipath), mailname])
|
||||
return read_config(inipath)
|
||||
|
||||
return make_conf
|
||||
|
||||
104
tests/test_cmdeploy.py
Normal file
104
tests/test_cmdeploy.py
Normal file
@@ -0,0 +1,104 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import pytest
|
||||
from deploy_chatmail.cmdeploy import get_parser, main
|
||||
from chatmaild.config import read_config
|
||||
|
||||
|
||||
class TestCmdline:
|
||||
def test_parser(self, capsys):
|
||||
parser = get_parser()
|
||||
parser.parse_args([])
|
||||
init = parser.parse_args(["init", "chat.example.org"])
|
||||
update = parser.parse_args(["install"])
|
||||
assert init and update
|
||||
|
||||
def test_init(self, tmpdir):
|
||||
tmpdir.chdir()
|
||||
main(["init", "chat.example.org"])
|
||||
inipath = tmpdir.join("chatmail.ini")
|
||||
config = read_config(inipath.strpath)
|
||||
assert config.mailname == "chat.example.org"
|
||||
|
||||
def test_no_args_description(self, capsys):
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
main([])
|
||||
assert excinfo.value.code == 0
|
||||
out, err = capsys.readouterr()
|
||||
assert "Collect webxdc" in out
|
||||
assert " init " in out and "Initialize config" in out
|
||||
|
||||
def test_version(self, capsys):
|
||||
with pytest.raises(SystemExit) as excinfo:
|
||||
main(["--version"])
|
||||
assert excinfo.value.code == 0
|
||||
out, err = capsys.readouterr()
|
||||
assert out.strip() == xdcget.__version__
|
||||
|
||||
def test_init_not_overwrite(self, tmpdir):
|
||||
tmpdir.chdir()
|
||||
main(["init"])
|
||||
with pytest.raises(SystemExit):
|
||||
main(["init"])
|
||||
|
||||
def test_update_from_different_dir(self, config_example1, tmp_path):
|
||||
p = tmp_path.joinpath("somewhere")
|
||||
p.mkdir()
|
||||
os.chdir(p)
|
||||
main(["--config", "../xdcget.ini", "update"])
|
||||
|
||||
def test_prune_index(self, iniconfig):
|
||||
iniconfig.add_source(
|
||||
app_id="webxdc-poll",
|
||||
source_code_url="https://codeberg.org/webxdc/poll",
|
||||
)
|
||||
iniconfig.add_lock_entry(
|
||||
app_id="webxdc-poll",
|
||||
name="Poll",
|
||||
tag_name="v1.0.1",
|
||||
url="https://codeberg.org/attachments/d53543bd-d805-4aba-926d-88eefc7a9eef",
|
||||
date="2023-07-05T20:30:48Z",
|
||||
cache_relname="webxdc-poll-v1.0.1.xdc",
|
||||
)
|
||||
iniconfig.add_lock_entry(
|
||||
app_id="webxdc-checklist",
|
||||
name="Checklist",
|
||||
tag_name="v0.0.2",
|
||||
url="https://codeberg.org/attachments/65d05b8d-a97c-4fb6-a534-e308c382f874",
|
||||
date="2023-07-07T18:05:19Z",
|
||||
cache_relname="webxdc-checklist-v0.0.2.xdc",
|
||||
)
|
||||
|
||||
config = iniconfig.create()
|
||||
assert "webxdc-poll" in config.index_path.read_text()
|
||||
assert "webxdc-checklist" in config.index_path.read_text()
|
||||
main(["update"])
|
||||
assert "webxdc-poll" in config.index_path.read_text()
|
||||
assert "webxdc-checklist" not in config.index_path.read_text()
|
||||
|
||||
def test_update_empty(self, iniconfig):
|
||||
iniconfig.create()
|
||||
with pytest.raises(SystemExit):
|
||||
main(["update"])
|
||||
|
||||
def test_update_no_network(self, capfd, config_example1, monkeypatch):
|
||||
main(["update"])
|
||||
p = config_example1.export_dir.joinpath("xdcget.lock")
|
||||
assert p.exists()
|
||||
assert len(p.read_text()) > 50
|
||||
monkeypatch.delattr(sys.modules["requests"], "get")
|
||||
main(["update", "--offline"])
|
||||
|
||||
def test_export_json(self, capfd, config_example1, monkeypatch):
|
||||
main(["update"])
|
||||
p = config_example1.export_dir.joinpath("xdcget-lock.json")
|
||||
assert p.exists()
|
||||
with p.open() as f:
|
||||
app_list = json.load(f)
|
||||
assert len(app_list) == 2
|
||||
checklist, poll = app_list
|
||||
p = config_example1.export_dir.joinpath(checklist["icon_relname"])
|
||||
assert p.exists() and "icon" in p.name
|
||||
p = config_example1.export_dir.joinpath(poll["icon_relname"])
|
||||
assert p.exists() and "icon" in p.name
|
||||
Reference in New Issue
Block a user