mirror of
https://github.com/arcan1s/ahriman.git
synced 2025-07-30 06:09:56 +00:00
Email report (#11)
* Demo email report implementation * improved ssl mode * correct default option spelling and more fields to be hidden for not extended reports
This commit is contained in:
105
tests/ahriman/core/report/test_email.py
Normal file
105
tests/ahriman/core/report/test_email.py
Normal file
@ -0,0 +1,105 @@
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report.email import Email
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_send(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must send an email with attachment
|
||||
"""
|
||||
smtp_mock = mocker.patch("smtplib.SMTP")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.starttls.assert_not_called()
|
||||
smtp_mock.return_value.login.assert_not_called()
|
||||
smtp_mock.return_value.sendmail.assert_called_once()
|
||||
smtp_mock.return_value.quit.assert_called_once()
|
||||
|
||||
|
||||
def test_send_auth(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must send an email with attachment with auth
|
||||
"""
|
||||
configuration.set("email", "user", "username")
|
||||
configuration.set("email", "password", "password")
|
||||
smtp_mock = mocker.patch("smtplib.SMTP")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.login.assert_called_once()
|
||||
|
||||
|
||||
def test_send_auth_no_password(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must send an email with attachment without auth if no password supplied
|
||||
"""
|
||||
configuration.set("email", "user", "username")
|
||||
smtp_mock = mocker.patch("smtplib.SMTP")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.login.assert_not_called()
|
||||
|
||||
|
||||
def test_send_auth_no_user(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must send an email with attachment without auth if no user supplied
|
||||
"""
|
||||
configuration.set("email", "password", "password")
|
||||
smtp_mock = mocker.patch("smtplib.SMTP")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.login.assert_not_called()
|
||||
|
||||
|
||||
def test_send_ssl_tls(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must send an email with attachment with ssl/tls
|
||||
"""
|
||||
configuration.set("email", "ssl", "ssl")
|
||||
smtp_mock = mocker.patch("smtplib.SMTP_SSL")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.starttls.assert_not_called()
|
||||
smtp_mock.return_value.login.assert_not_called()
|
||||
smtp_mock.return_value.sendmail.assert_called_once()
|
||||
smtp_mock.return_value.quit.assert_called_once()
|
||||
|
||||
|
||||
def test_send_starttls(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must send an email with attachment with starttls
|
||||
"""
|
||||
configuration.set("email", "ssl", "starttls")
|
||||
smtp_mock = mocker.patch("smtplib.SMTP")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report._send("a text", {"attachment.html": "an attachment"})
|
||||
smtp_mock.return_value.starttls.assert_called_once()
|
||||
|
||||
|
||||
def test_generate(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report
|
||||
"""
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report.generate([package_ahriman], [])
|
||||
send_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_generate_with_built(configuration: Configuration, package_ahriman: Package, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate report with built packages
|
||||
"""
|
||||
send_mock = mocker.patch("ahriman.core.report.email.Email._send")
|
||||
|
||||
report = Email("x86_64", configuration)
|
||||
report.generate([package_ahriman], [package_ahriman])
|
||||
send_mock.assert_called_once()
|
@ -12,5 +12,5 @@ def test_generate(configuration: Configuration, package_ahriman: Package, mocker
|
||||
write_mock = mocker.patch("pathlib.Path.write_text")
|
||||
|
||||
report = HTML("x86_64", configuration)
|
||||
report.generate([package_ahriman])
|
||||
report.generate([package_ahriman], [])
|
||||
write_mock.assert_called_once()
|
||||
|
19
tests/ahriman/core/report/test_jinja_tempalte.py
Normal file
19
tests/ahriman/core/report/test_jinja_tempalte.py
Normal file
@ -0,0 +1,19 @@
|
||||
from ahriman.core.configuration import Configuration
|
||||
from ahriman.core.report.jinja_template import JinjaTemplate
|
||||
from ahriman.models.package import Package
|
||||
|
||||
|
||||
def test_generate(configuration: Configuration, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must generate html report
|
||||
"""
|
||||
report = JinjaTemplate("html", configuration)
|
||||
assert report.make_html([package_ahriman], extended_report=False)
|
||||
|
||||
|
||||
def test_generate_extended(configuration: Configuration, package_ahriman: Package) -> None:
|
||||
"""
|
||||
must generate extended html report
|
||||
"""
|
||||
report = JinjaTemplate("html", configuration)
|
||||
assert report.make_html([package_ahriman], extended_report=True)
|
@ -15,7 +15,7 @@ def test_report_failure(configuration: Configuration, mocker: MockerFixture) ->
|
||||
"""
|
||||
mocker.patch("ahriman.core.report.html.HTML.generate", side_effect=Exception())
|
||||
with pytest.raises(ReportFailed):
|
||||
Report.load("x86_64", configuration, ReportSettings.HTML.name).run(Path("path"))
|
||||
Report.load("x86_64", configuration, ReportSettings.HTML.name).run(Path("path"), [])
|
||||
|
||||
|
||||
def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -24,7 +24,16 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
"""
|
||||
mocker.patch("ahriman.models.report_settings.ReportSettings.from_option", return_value=ReportSettings.Disabled)
|
||||
report_mock = mocker.patch("ahriman.core.report.report.Report.generate")
|
||||
Report.load("x86_64", configuration, ReportSettings.Disabled.name).run(Path("path"))
|
||||
Report.load("x86_64", configuration, ReportSettings.Disabled.name).run(Path("path"), [])
|
||||
report_mock.assert_called_once()
|
||||
|
||||
|
||||
def test_report_email(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
must generate email report
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.email.Email.generate")
|
||||
Report.load("x86_64", configuration, ReportSettings.Email.name).run(Path("path"), [])
|
||||
report_mock.assert_called_once()
|
||||
|
||||
|
||||
@ -33,5 +42,5 @@ def test_report_html(configuration: Configuration, mocker: MockerFixture) -> Non
|
||||
must generate html report
|
||||
"""
|
||||
report_mock = mocker.patch("ahriman.core.report.html.HTML.generate")
|
||||
Report.load("x86_64", configuration, ReportSettings.HTML.name).run(Path("path"))
|
||||
Report.load("x86_64", configuration, ReportSettings.HTML.name).run(Path("path"), [])
|
||||
report_mock.assert_called_once()
|
||||
|
@ -133,7 +133,7 @@ def test_process_report(executor: Executor, package_ahriman: Package, mocker: Mo
|
||||
mocker.patch("ahriman.core.report.report.Report.load", return_value=Report("x86_64", executor.configuration))
|
||||
report_mock = mocker.patch("ahriman.core.report.report.Report.run")
|
||||
|
||||
executor.process_report(["dummy"])
|
||||
executor.process_report(["dummy"], [])
|
||||
report_mock.assert_called_once()
|
||||
|
||||
|
||||
@ -143,7 +143,7 @@ def test_process_report_auto(executor: Executor, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
configuration_getlist_mock = mocker.patch("ahriman.core.configuration.Configuration.getlist")
|
||||
|
||||
executor.process_report(None)
|
||||
executor.process_report(None, [])
|
||||
configuration_getlist_mock.assert_called_once()
|
||||
|
||||
|
||||
@ -154,7 +154,7 @@ def test_process_upload(executor: Executor, mocker: MockerFixture) -> None:
|
||||
mocker.patch("ahriman.core.upload.upload.Upload.load", return_value=Upload("x86_64", executor.configuration))
|
||||
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.run")
|
||||
|
||||
executor.process_sync(["dummy"])
|
||||
executor.process_sync(["dummy"], [])
|
||||
upload_mock.assert_called_once()
|
||||
|
||||
|
||||
@ -164,7 +164,7 @@ def test_process_upload_auto(executor: Executor, mocker: MockerFixture) -> None:
|
||||
"""
|
||||
configuration_getlist_mock = mocker.patch("ahriman.core.configuration.Configuration.getlist")
|
||||
|
||||
executor.process_sync(None)
|
||||
executor.process_sync(None, [])
|
||||
configuration_getlist_mock.assert_called_once()
|
||||
|
||||
|
||||
|
@ -12,5 +12,5 @@ def test_sync(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.upload.rsync.Rsync._check_output")
|
||||
|
||||
upload = Rsync("x86_64", configuration)
|
||||
upload.sync(Path("path"))
|
||||
upload.sync(Path("path"), [])
|
||||
check_output_mock.assert_called_once()
|
||||
|
@ -12,5 +12,5 @@ def test_sync(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
check_output_mock = mocker.patch("ahriman.core.upload.s3.S3._check_output")
|
||||
|
||||
upload = S3("x86_64", configuration)
|
||||
upload.sync(Path("path"))
|
||||
upload.sync(Path("path"), [])
|
||||
check_output_mock.assert_called_once()
|
||||
|
@ -15,7 +15,7 @@ def test_upload_failure(configuration: Configuration, mocker: MockerFixture) ->
|
||||
"""
|
||||
mocker.patch("ahriman.core.upload.rsync.Rsync.sync", side_effect=Exception())
|
||||
with pytest.raises(SyncFailed):
|
||||
Upload.load("x86_64", configuration, UploadSettings.Rsync.name).run(Path("path"))
|
||||
Upload.load("x86_64", configuration, UploadSettings.Rsync.name).run(Path("path"), [])
|
||||
|
||||
|
||||
def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
@ -24,7 +24,7 @@ def test_report_dummy(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
"""
|
||||
mocker.patch("ahriman.models.upload_settings.UploadSettings.from_option", return_value=UploadSettings.Disabled)
|
||||
upload_mock = mocker.patch("ahriman.core.upload.upload.Upload.sync")
|
||||
Upload.load("x86_64", configuration, UploadSettings.Disabled.name).run(Path("path"))
|
||||
Upload.load("x86_64", configuration, UploadSettings.Disabled.name).run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ def test_upload_rsync(configuration: Configuration, mocker: MockerFixture) -> No
|
||||
must upload via rsync
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.rsync.Rsync.sync")
|
||||
Upload.load("x86_64", configuration, UploadSettings.Rsync.name).run(Path("path"))
|
||||
Upload.load("x86_64", configuration, UploadSettings.Rsync.name).run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
|
||||
|
||||
@ -42,5 +42,5 @@ def test_upload_s3(configuration: Configuration, mocker: MockerFixture) -> None:
|
||||
must upload via s3
|
||||
"""
|
||||
upload_mock = mocker.patch("ahriman.core.upload.s3.S3.sync")
|
||||
Upload.load("x86_64", configuration, UploadSettings.S3.name).run(Path("path"))
|
||||
Upload.load("x86_64", configuration, UploadSettings.S3.name).run(Path("path"), [])
|
||||
upload_mock.assert_called_once()
|
||||
|
Reference in New Issue
Block a user