mirror of
https://seed.flo-the.dev/z3gWc1qgaeZaoGwL4WTstLNoqjayM.git
synced 2025-12-06 04:47:35 +01:00
add CLI test
Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
@@ -46,6 +46,7 @@
|
|||||||
isort.settings.flags = "--profile black";
|
isort.settings.flags = "--profile black";
|
||||||
pylint.enable = false; # doesn't work correctly with module imports in flake
|
pylint.enable = false; # doesn't work correctly with module imports in flake
|
||||||
detect-private-keys.enable = true;
|
detect-private-keys.enable = true;
|
||||||
|
detect-private-keys.excludes = [ "tests/" ];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
app = self.packages.${system}.smtprd-ng;
|
app = self.packages.${system}.smtprd-ng;
|
||||||
|
|||||||
@@ -400,11 +400,16 @@ class SMTPServer(Controller):
|
|||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def main() -> int:
|
def parse_args(args=None) -> argparse.ArgumentParser.parse_args:
|
||||||
"""Main routine
|
"""Parse arguments
|
||||||
|
|
||||||
Returns:
|
Parameters
|
||||||
int: exit code
|
----------
|
||||||
|
args : List of strings
|
||||||
|
|
||||||
|
Returns
|
||||||
|
-------
|
||||||
|
argparse.ArgumentParser.parse_args : Namespace of arguments
|
||||||
"""
|
"""
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description=__doc__.strip(),
|
description=__doc__.strip(),
|
||||||
@@ -417,9 +422,21 @@ def main() -> int:
|
|||||||
default="./config.ini",
|
default="./config.ini",
|
||||||
help="configuration file",
|
help="configuration file",
|
||||||
)
|
)
|
||||||
args = parser.parse_args()
|
return parser.parse_args(args)
|
||||||
setlocale(LC_ALL, "C") # for strftime
|
|
||||||
|
|
||||||
|
|
||||||
|
def main(args=None) -> int:
|
||||||
|
"""Main routine
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
int: exit code
|
||||||
|
"""
|
||||||
|
args = parse_args(args)
|
||||||
|
setlocale(LC_ALL, "C") # for strftime
|
||||||
|
if len(args.config) == 0:
|
||||||
|
raise OSError("No config file supplied")
|
||||||
|
if not Path(args.config).is_file():
|
||||||
|
raise OSError("Config file not found: " + str(args.config))
|
||||||
try:
|
try:
|
||||||
config: Config = Config.from_ini(args.config)
|
config: Config = Config.from_ini(args.config)
|
||||||
except RuntimeError as e:
|
except RuntimeError as e:
|
||||||
|
|||||||
@@ -19,12 +19,14 @@
|
|||||||
Tests for smtprd_ng
|
Tests for smtprd_ng
|
||||||
"""
|
"""
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
|
# pylint: disable=unused-argument
|
||||||
|
|
||||||
import configparser
|
import configparser
|
||||||
import email
|
import email
|
||||||
import email.message
|
import email.message
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
import pytest
|
||||||
from M2Crypto import BIO, SMIME, X509
|
from M2Crypto import BIO, SMIME, X509
|
||||||
|
|
||||||
from smtprd_ng import smtprd
|
from smtprd_ng import smtprd
|
||||||
@@ -134,3 +136,21 @@ def test_client_sign():
|
|||||||
p7, data = SMIME.smime_load_pkcs7_bio(buf)
|
p7, data = SMIME.smime_load_pkcs7_bio(buf)
|
||||||
v = s.verify(p7, data)
|
v = s.verify(p7, data)
|
||||||
assert "Test to sign" in v.decode()
|
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"
|
||||||
|
|||||||
Reference in New Issue
Block a user