add CLI test

Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
2024-07-09 18:57:58 +02:00
parent 81fa631d16
commit d9053e36bc
3 changed files with 44 additions and 6 deletions

View File

@@ -19,12 +19,14 @@
Tests for smtprd_ng
"""
# pylint: disable=protected-access
# pylint: disable=unused-argument
import configparser
import email
import email.message
from pathlib import Path
import pytest
from M2Crypto import BIO, SMIME, X509
from smtprd_ng import smtprd
@@ -134,3 +136,21 @@ def test_client_sign():
p7, data = SMIME.smime_load_pkcs7_bio(buf)
v = s.verify(p7, data)
assert "Test to sign" in v.decode()
def test_cli_no_config_file(capsys):
"""Test whether config file parameter is supplied"""
test_args = ["--config", ""]
with pytest.raises(Exception) as e_info:
smtprd.main(test_args)
assert e_info.typename == "OSError"
assert str(e_info.value) == "No config file supplied"
def test_cli_config_file_not_found(capsys):
"""Test whether config file is found"""
test_args = ["--config", "doesnotexist.conf"]
with pytest.raises(Exception) as e_info:
smtprd.main(test_args)
assert e_info.typename == "OSError"
assert str(e_info.value) == "Config file not found: doesnotexist.conf"