diff --git a/.gitignore b/.gitignore index 9bbe995..ba9b650 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,9 @@ config.ini *.pem # nix -result \ No newline at end of file +result + +# python +*.pyc +__pycache__ +.coverage \ No newline at end of file diff --git a/default.nix b/default.nix index 05aa0d8..59ce8f2 100644 --- a/default.nix +++ b/default.nix @@ -19,7 +19,7 @@ pkgs.python3Packages.buildPythonPackage rec { cryptography ]; - # nativeCheckInputs = [ pkgs.python3Packages.pytestCheckHook ]; + nativeCheckInputs = [ pkgs.python3Packages.pytestCheckHook ]; pythonImportsCheck = [ "smtprd_ng" ]; meta = { diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/test_smtprd_ng.py b/tests/test_smtprd_ng.py new file mode 100644 index 0000000..ceb5486 --- /dev/null +++ b/tests/test_smtprd_ng.py @@ -0,0 +1,46 @@ +# SMTP forwarding relay daemon with signing and encryption +# +# Copyright (C) 2024 F. Brandes (additions to original code) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +""" +Tests for smtprd_ng +""" +# pylint: disable=protected-access + +import configparser +from pathlib import Path + +from smtprd_ng import smtprd + + +def test_config_from_config(): + """Test opening and readig the config file""" + config_parser: configparser.ConfigParser = configparser.ConfigParser() + with open(Path("config.example"), "r", encoding="utf8") as fp: + config_parser.read_file(fp) + cfg = smtprd.Config._from_config(config_parser) + assert cfg.server.hostname == "localhost" + assert cfg.client.port == 465 + assert cfg.client.smime_cert == "" + + +def test_config_from_ini(): + """Test parsing the config file and using fallbacks""" + cfg = smtprd.Config.from_ini(Path("config.example")) + assert cfg.server.hostname == "localhost" + assert cfg.client.port == 465 + assert cfg.client.smime_cert == "" + assert cfg.client.use_tls is True