fix tests and run all tests on "cmdeploy test"

This commit is contained in:
holger krekel
2023-12-11 12:18:10 +01:00
parent 613d3e14ea
commit 3f2eb84323
2 changed files with 21 additions and 9 deletions

View File

@@ -1,25 +1,33 @@
import os
import pytest
from deploy_chatmail.cmdeploy import get_parser, main
from chatmaild.config import read_config
@pytest.fixture(autouse=True)
def _chdir(tmp_path):
old = os.getcwd()
os.chdir(tmp_path)
yield
os.chdir(old)
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
run = parser.parse_args(["run"])
assert init and run
def test_init(self, tmpdir):
tmpdir.chdir()
def test_init(self, tmp_path):
main(["init", "chat.example.org"])
inipath = tmpdir.join("chatmail.ini")
inipath = tmp_path.joinpath("chatmail.ini")
config = read_config(inipath.strpath)
assert config.mailname == "chat.example.org"
def test_init_not_overwrite(self, tmpdir):
tmpdir.chdir()
def test_init_not_overwrite(self):
main(["init", "chat.example.org"])
with pytest.raises(SystemExit):
main(["init", "chat.example.org"])