#43 Move the email sending code from the toddlers to the notify module
Merged 3 years ago by pingou. Opened 3 years ago by pingou.

@@ -86,7 +86,7 @@ 

  

      @patch("toddlers.utils.fedora_account.set_fas", new=Mock(return_value=True))

      @patch("toddlers.utils.bugzilla_system.set_bz", new=Mock(return_value=True))

-     @patch("toddlers.plugins.check_email_overrides.send_email")

+     @patch("toddlers.utils.notify.send_email")

      @patch("toddlers.utils.fedora_account.get_user_by_email")

      @patch("toddlers.utils.bugzilla_system.get_user")

      def test_process_no_fas(self, get_user, get_user_by_email, send_email, toddler):
@@ -126,7 +126,7 @@ 

  

      @patch("toddlers.utils.fedora_account.set_fas", new=Mock(return_value=True))

      @patch("toddlers.utils.bugzilla_system.set_bz", new=Mock(return_value=True))

-     @patch("toddlers.plugins.check_email_overrides.send_email")

+     @patch("toddlers.utils.notify.send_email")

      @patch("toddlers.utils.fedora_account.get_user_by_email")

      @patch("toddlers.utils.bugzilla_system.get_user")

      def test_process_no_bz(self, get_user, get_user_by_email, send_email, toddler):

@@ -69,7 +69,7 @@ 

          ):

              assert toddler.process(config=config, message=msg) is None

  

-     @patch("toddlers.plugins.clean_retired_packages.send_email")

+     @patch("toddlers.utils.notify.send_email")

      def test_process(self, send_email, toddler, caplog):

          pdc_branches = MagicMock()

          pdc_branches.json.return_value = {

@@ -17,8 +17,8 @@ 

  from toddlers.base import ToddlerBase

  from toddlers.utils import bugzilla_system

  from toddlers.utils import fedora_account

+ from toddlers.utils import notify

  from toddlers.utils.misc import merge_dicts

- from toddlers.utils.notify import send_email

  from toddlers.utils.requests import make_session

  

  
@@ -93,28 +93,12 @@ 

          if logs:

              _log.info("- %s", "\n- ".join(logs))

              logs_text = "\n- ".join(logs)

-             message = f"""Dear Admin,

- 

- In the email_overrides.toml file located at:

- {url}

- 

- We have identified the following issues:

- - {logs_text}

- 

- Overrides having no FAS account can be simply removed.

- 

- Overrides having no bugzilla account needs to be notified to the person.

- 

- 

- Have a wonderful day and see you (maybe?) at the next run!

- 

- """

-             send_email(

+             notify.notify_admins_on_invalid_entry_in_email_override(

                  to_addresses=[config["admin_email"]],

                  from_address=config["admin_email"],

-                 subject="Invalid entries in email_overrides.toml",

-                 content=message,

                  mail_server=config["mail_server"],

+                 url=url,

+                 logs_text=logs_text,

              )

  

  

@@ -13,7 +13,7 @@ 

  import logging

  

  from toddlers.base import ToddlerBase

- from toddlers.utils.notify import send_email

+ from toddlers.utils import notify

  from toddlers.utils.requests import make_session

  

  
@@ -141,24 +141,11 @@ 

  

          if logs:

              logs_text = "\n- ".join(logs)

-             message = f"""Dear Admin,

- 

- The clean_retired_packages toddler just ran and adjusted some retired packages

- for recording purposes, here is what it did:

- - {logs_text}

- 

- In case someone asks, you can come back to this email but there isn't really

- anything else to do with it.

- 

- Have a wonderful day and see you (maybe?) at the next run!

- 

- """

-             send_email(

+             notify.notify_admins_on_retired_packages_cleanup(

                  to_addresses=[config["admin_email"]],

                  from_address=config["admin_email"],

-                 subject="Toddlers cleaned up some retired packages",

-                 content=message,

                  mail_server=config["mail_server"],

+                 logs_text=logs_text,

              )

  

      def orphan_package(self, namespace, name, current_poc):

file modified
+52
@@ -139,6 +139,30 @@ 

      )

  

  

+ def notify_admins_on_retired_packages_cleanup(

+     to_addresses, from_address, mail_server, logs_text

+ ):

+     message = f"""Dear Admin,

+ 

+ The clean_retired_packages toddler just ran and adjusted some retired packages

+ for recording purposes, here is what it did:

+ - {logs_text}

+ 

+ In case someone asks, you can come back to this email but there isn't really

+ anything else to do with it.

+ 

+ Have a wonderful day and see you (maybe?) at the next run!

+ 

+ """

+     send_email(

+         to_addresses=to_addresses,

+         from_address=from_address,

+         subject="Toddlers cleaned up some retired packages",

+         content=message,

+         mail_server=mail_server,

+     )

+ 

+ 

  def notify_packager_distgit_sync_error(

      mail_server, admin_email, user_email, cc_address

  ):
@@ -195,6 +219,34 @@ 

      )

  

  

+ def notify_admins_on_invalid_entry_in_email_override(

+     to_addresses, from_address, mail_server, url, logs_text

+ ):

+     message = f"""Dear Admin,

+ 

+ In the email_overrides.toml file located at:

+ {url}

+ 

+ We have identified the following issues:

+ - {logs_text}

+ 

+ Overrides having no FAS account can be simply removed.

+ 

+ Overrides having no bugzilla account needs to be notified to the person.

+ 

+ 

+ Have a wonderful day and see you (maybe?) at the next run!

+ 

+ """

+     send_email(

+         to_addresses=to_addresses,

+         from_address=from_address,

+         subject="Invalid entries in email_overrides.toml",

+         content=message,

+         mail_server=mail_server,

+     )

+ 

+ 

  def send_email(

      to_addresses, from_address, subject, content, mail_server, cc_address=None

  ):

This is for two reasons: a) keep the toddler shorter and simpler/easier
to read and b) be consistent with the other toddlers.

Signed-off-by: Pierre-Yves Chibon pingou@pingoured.fr

Build succeeded.

  • tox : SUCCESS in 5m 58s

Oups looks like I forgot to merge this one :s

rebased onto 8a03c4a

3 years ago

Build succeeded.

  • tox : SUCCESS in 6m 04s

Pull-Request has been merged by pingou

3 years ago