add first tests

Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
2024-07-06 12:58:50 +02:00
parent 7f37e875ed
commit 2b253e03eb
4 changed files with 53 additions and 2 deletions

7
.gitignore vendored
View File

@@ -14,4 +14,9 @@ config.ini
*.pem *.pem
# nix # nix
result result
# python
*.pyc
__pycache__
.coverage

View File

@@ -19,7 +19,7 @@ pkgs.python3Packages.buildPythonPackage rec {
cryptography cryptography
]; ];
# nativeCheckInputs = [ pkgs.python3Packages.pytestCheckHook ]; nativeCheckInputs = [ pkgs.python3Packages.pytestCheckHook ];
pythonImportsCheck = [ "smtprd_ng" ]; pythonImportsCheck = [ "smtprd_ng" ];
meta = { meta = {

0
tests/__init__.py Normal file
View File

46
tests/test_smtprd_ng.py Normal file
View File

@@ -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 <http://www.gnu.org/licenses/>.
"""
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