mirror of
https://seed.flo-the.dev/z3gWc1qgaeZaoGwL4WTstLNoqjayM.git
synced 2025-12-06 04:47:35 +01:00
add reading password from file
Signed-off-by: Florian Brandes <florian.brandes@posteo.de>
This commit is contained in:
@@ -19,7 +19,6 @@
|
||||
Tests for smtprd_ng
|
||||
"""
|
||||
# pylint: disable=protected-access
|
||||
# pylint: disable=unused-argument
|
||||
|
||||
import configparser
|
||||
import email
|
||||
@@ -68,6 +67,7 @@ def test_config_from_config():
|
||||
assert cfg.client.port == 465
|
||||
assert cfg.client.smime_cert == ""
|
||||
assert cfg.client.use_tls is True
|
||||
assert cfg.client.password == ""
|
||||
|
||||
|
||||
def test_config_from_ini():
|
||||
@@ -80,6 +80,24 @@ def test_config_from_ini():
|
||||
assert cfg.client.use_tls is True
|
||||
|
||||
|
||||
def test_read_from_file():
|
||||
"""Test read_from_file function and the fallback"""
|
||||
existing_file = "config.example"
|
||||
non_existing_file = "abcde"
|
||||
empty_file = "tests/__init__.py"
|
||||
empty_string = ""
|
||||
assert smtprd.Config._read_from_file(existing_file) == "# [server]"
|
||||
with pytest.raises(Exception) as e_info:
|
||||
smtprd.Config._read_from_file(non_existing_file)
|
||||
assert e_info.typename == "OSError"
|
||||
assert str(e_info.value) == "File wasn't found: abcde"
|
||||
assert smtprd.Config._read_from_file(empty_string) == ""
|
||||
with pytest.raises(Exception) as e_info:
|
||||
smtprd.Config._read_from_file(empty_file)
|
||||
assert e_info.typename == "OSError"
|
||||
assert str(e_info.value) == "Empty file supplied: tests/__init__.py"
|
||||
|
||||
|
||||
def test_config_emailcerts():
|
||||
"""test retrieval of email/cert pair"""
|
||||
email_list = [("email1", "cert1"), ("email2", "cert2")]
|
||||
@@ -153,7 +171,7 @@ def test_client_sign():
|
||||
assert "Test to sign" in v.decode()
|
||||
|
||||
|
||||
def test_cli_no_config_file(capsys):
|
||||
def test_cli_no_config_file():
|
||||
"""Test whether config file parameter is supplied"""
|
||||
test_args = ["--config", ""]
|
||||
with pytest.raises(Exception) as e_info:
|
||||
@@ -162,7 +180,7 @@ def test_cli_no_config_file(capsys):
|
||||
assert str(e_info.value) == "No config file supplied"
|
||||
|
||||
|
||||
def test_cli_config_file_not_found(capsys):
|
||||
def test_cli_config_file_not_found():
|
||||
"""Test whether config file is found"""
|
||||
test_args = ["--config", "doesnotexist.conf"]
|
||||
with pytest.raises(Exception) as e_info:
|
||||
|
||||
Reference in New Issue
Block a user