예제 #1
0
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()
예제 #2
0
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()
예제 #3
0
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()
예제 #4
0
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()
예제 #5
0
def test_generate_no_empty_with_built(configuration: Configuration,
                                      package_ahriman: Package,
                                      mocker: MockerFixture) -> None:
    """
    must generate report with built packages if no_empty_report is set
    """
    configuration.set("email", "no_empty_report", "yes")
    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()
예제 #6
0
파일: report.py 프로젝트: arcan1s/ahriman
 def load(cls: Type[Report], architecture: str,
          configuration: Configuration, target: str) -> Report:
     """
     load client from settings
     :param architecture: repository architecture
     :param configuration: configuration instance
     :param target: target to generate report (e.g. html)
     :return: client according to current settings
     """
     provider = ReportSettings.from_option(target)
     if provider == ReportSettings.HTML:
         from ahriman.core.report.html import HTML
         return HTML(architecture, configuration)
     if provider == ReportSettings.Email:
         from ahriman.core.report.email import Email
         return Email(architecture, configuration)
     return cls(architecture, configuration)  # should never happen