feat(cleaner): ✨ add command prune
this new command will be called by cron-like process to clean purge old logs and old mails. All files were formatted and mail_utils was renamed in utils since it now defines utility function not only for mail functions.
This commit is contained in:
+26
-8
@@ -11,23 +11,37 @@ def mock_get_or_create_folder(account, folder_name): # noqa: D103
|
||||
return folder_name
|
||||
|
||||
|
||||
@pytest.mark.parametrize("vars", [("N2_REPORT_SUBJECT", "N2_REPORT_RECIPIENTS"), ("N2_REPORT_RECIPIENTS", "N2_REPORT_SUBJECT")])
|
||||
def test_send_n2_report_missing_recipients_env(vars, monkeypatch, ):
|
||||
@pytest.mark.parametrize(
|
||||
"vars",
|
||||
[
|
||||
("N2_REPORT_SUBJECT", "N2_REPORT_RECIPIENTS"),
|
||||
("N2_REPORT_RECIPIENTS", "N2_REPORT_SUBJECT"),
|
||||
],
|
||||
)
|
||||
def test_send_n2_report_missing_recipients_env(vars, monkeypatch):
|
||||
"""Assert that missing values in environmnent file raises KeyError."""
|
||||
monkeypatch.delenv("N2_REPORT_RECIPIENTS")
|
||||
monkeypatch.delenv("N2_REPORT_SUBJECT")
|
||||
monkeypatch.setenv(vars[0], "test")
|
||||
|
||||
|
||||
with pytest.raises(KeyError) as err:
|
||||
send_n2_report(account=MagicMock(), summary="summary", n2_log_file=MagicMock())
|
||||
|
||||
assert vars[1] in err.value.args
|
||||
|
||||
|
||||
@pytest.mark.parametrize("recipients", ["mail@client.fr", "mail@ client.fr ", "mail1@client.fr,mail2@client.fr,mail3@client.fr", "mail1@client.fr , mail2@client.fr , mail3@client.fr"])
|
||||
@pytest.mark.parametrize(
|
||||
"recipients",
|
||||
[
|
||||
"mail@client.fr",
|
||||
"mail@ client.fr ",
|
||||
"mail1@client.fr,mail2@client.fr,mail3@client.fr",
|
||||
"mail1@client.fr , mail2@client.fr , mail3@client.fr",
|
||||
],
|
||||
)
|
||||
def test_send_n2_report_multiple_recipients(recipients, make_mock_account, monkeypatch):
|
||||
"""Assert gathering multiple account as recipients from env file is valid.
|
||||
|
||||
|
||||
Tests with value having space characters.
|
||||
Mails must be seperated by a comma.
|
||||
|
||||
@@ -35,12 +49,16 @@ def test_send_n2_report_multiple_recipients(recipients, make_mock_account, monke
|
||||
recipients: e-mail recipients in one string
|
||||
make_mock_account: return a fake account used for tests
|
||||
monkeypatch: used to change environment variables and functions accross the script
|
||||
|
||||
|
||||
"""
|
||||
monkeypatch.setenv("N2_REPORT_SUBJECT", "test")
|
||||
monkeypatch.setenv("N2_REPORT_RECIPIENTS", "mail@client.fr")
|
||||
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr("logwatcher.notifier.get_or_create_folder", mock_get_or_create_folder)
|
||||
m.setattr("logwatcher.notifier.Message.send", MagicMock(id="1", return_value=None))
|
||||
send_n2_report(account=make_mock_account(), summary="summary", n2_log_file=MagicMock())
|
||||
m.setattr(
|
||||
"logwatcher.notifier.Message.send", MagicMock(id="1", return_value=None)
|
||||
)
|
||||
send_n2_report(
|
||||
account=make_mock_account(), summary="summary", n2_log_file=MagicMock()
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user