Skip to content

Commit

Permalink
Fix broken tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreben committed Nov 6, 2024
1 parent ec1294f commit 8f3a223
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 54 deletions.
36 changes: 18 additions & 18 deletions libsys_airflow/plugins/digital_bookplates/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
from airflow.decorators import task
from airflow.models import Variable

from libsys_airflow.plugins.shared.utils import is_production
from libsys_airflow.plugins.shared.utils import send_email_with_server_name
from libsys_airflow.plugins.shared.utils import (
is_production,
send_email_with_server_name,
)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -133,6 +135,15 @@ def _summary_add_979_email(dag_runs: list, folio_url: str) -> str:
).render(dag_runs=dag_runs, folio_url=folio_url, dag_url=dag_url)


def _to_addresses():
devs_to_email_addr = Variable.get("EMAIL_DEVS")
bookplates_email_addr = Variable.get("BOOKPLATES_EMAIL")
addresses = [devs_to_email_addr]
if is_production():
addresses.append(bookplates_email_addr)
return addresses


@task
def bookplates_metadata_email(**kwargs):
"""
Expand Down Expand Up @@ -165,7 +176,7 @@ def bookplates_metadata_email(**kwargs):
)

send_email_with_server_name(
to=to_addresses(),
to=_to_addresses(),
subject="Digital bookplates new and updated metadata",
html_content=html_content,
)
Expand All @@ -185,7 +196,7 @@ def deleted_from_argo_email(**kwargs):
html_content = _deleted_from_argo_email_body(deleted_druids)

send_email_with_server_name(
to=to_addresses(),
to=_to_addresses(),
subject="Deleted Druids from Argo for Digital bookplates",
html_content=html_content,
)
Expand All @@ -202,7 +213,7 @@ def missing_fields_email(**kwargs):
html_content = _missing_fields_body(failures)

send_email_with_server_name(
to=to_addresses(),
to=_to_addresses(),
subject="Missing Fields for Digital Bookplates",
html_content=html_content,
)
Expand All @@ -214,26 +225,15 @@ def missing_fields_email(**kwargs):
def summary_add_979_dag_runs(**kwargs):
dag_runs = kwargs["dag_runs"]
additional_email = kwargs.get("email")

folio_url = Variable.get("FOLIO_URL")
devs_to_email_addr = Variable.get("EMAIL_DEVS")

to_emails = [devs_to_email_addr]
to_emails = _to_addresses()
if additional_email:
to_emails.append(additional_email)
html_content = _summary_add_979_email(dag_runs, folio_url)

send_email_with_server_name(
to=to_addresses(),
to=to_emails,
subject="Summary of Adding 979 fields to MARC Workflows",
html_content=html_content,
)


def to_addresses():
devs_to_email_addr = Variable.get("EMAIL_DEVS")
bookplates_email_addr = Variable.get("BOOKPLATES_EMAIL")
addresses = [devs_to_email_addr]
if is_production():
addresses.append(bookplates_email_addr)
return addresses
2 changes: 1 addition & 1 deletion libsys_airflow/plugins/shared/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@


def is_production():
return bool(Variable.get("OKAPI_URL").find("prod") > 0)
return Variable.get("OKAPI_URL").find("prod") > 0


def send_email_with_server_name(**kwargs):
Expand Down
53 changes: 18 additions & 35 deletions tests/digital_bookplates/test_bookplates_emails.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def test_bookplates_metadata_email(
mocker, mock_bookplate_metadata, mock_folio_variables
):

mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name",
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

bookplates_metadata_email.function(
new=mock_bookplate_metadata["new"], updated=mock_bookplate_metadata["updated"]
Expand Down Expand Up @@ -121,9 +119,7 @@ def test_bookplates_metadata_email(


def test_bookplates_metadata_email_none(mocker, mock_folio_variables, caplog):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

bookplates_metadata_email.function(new=None, updated=None)

Expand All @@ -138,9 +134,7 @@ def test_no_new_bookplates_metadata_email(
mocker, mock_bookplate_metadata, mock_folio_variables, caplog
):

mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

bookplates_metadata_email.function(
new=[], updated=mock_bookplate_metadata["updated"]
Expand Down Expand Up @@ -173,9 +167,7 @@ def test_no_updated_bookplates_metadata_email(
mocker, mock_bookplate_metadata, mock_folio_variables, caplog
):

mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

bookplates_metadata_email.function(
new=mock_bookplate_metadata["new"],
Expand All @@ -201,9 +193,7 @@ def test_no_updated_bookplates_metadata_email(

def test_deleted_from_argo_email(mocker, mock_folio_variables):

mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

deleted_druids_info = [
{"title": "The Happy Fund", "druid": "ab123xy4567", "fund_name": "HAPY"}
Expand All @@ -226,9 +216,7 @@ def test_deleted_from_argo_email(mocker, mock_folio_variables):


def test_deleted_from_argo_email_no_druids(mocker, caplog):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

deleted_from_argo_email.function(deleted_druids=[])

Expand All @@ -237,12 +225,10 @@ def test_deleted_from_argo_email_no_druids(mocker, caplog):


def test_deleted_from_argo_email_prod(mocker, mock_folio_variables, caplog):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.is_production",
"libsys_airflow.plugins.shared.utils.is_production",
return_value=True,
)

Expand All @@ -254,9 +240,7 @@ def test_deleted_from_argo_email_prod(mocker, mock_folio_variables, caplog):


def test_missing_fields_email(mocker, mock_folio_variables):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

missing_fields_email.function(failures=failures)

Expand Down Expand Up @@ -284,12 +268,10 @@ def test_missing_fields_email_no_failures(mock_folio_variables, caplog):


def test_missing_fields_email_prod(mocker, mock_folio_variables):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.is_production",
"libsys_airflow.plugins.shared.utils.is_production",
return_value=True,
)

Expand All @@ -301,9 +283,7 @@ def test_missing_fields_email_prod(mocker, mock_folio_variables):


def test_summary_add_979_dag_runs(mocker, mock_folio_variables):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
)
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.conf.get",
Expand Down Expand Up @@ -357,8 +337,11 @@ def test_summary_add_979_dag_runs(mocker, mock_folio_variables):


def test_summary_add_979_dag_runs_prod(mocker, mock_folio_variables):
mock_send_email = mocker.patch(
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")

mocker.patch(
"libsys_airflow.plugins.shared.utils.is_production",
return_value=True,
)

mocker.patch(
Expand All @@ -374,6 +357,6 @@ def test_summary_add_979_dag_runs_prod(mocker, mock_folio_variables):

assert mock_send_email.call_args[1]["to"] == [
'[email protected]',
'[email protected]',
'[email protected]',
'[email protected]',
]

0 comments on commit 8f3a223

Please sign in to comment.