Skip to content

Commit 8f3a223

Browse files
committed
Fix broken tests
1 parent ec1294f commit 8f3a223

File tree

3 files changed

+37
-54
lines changed

3 files changed

+37
-54
lines changed

libsys_airflow/plugins/digital_bookplates/email.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
from airflow.decorators import task
77
from airflow.models import Variable
88

9-
from libsys_airflow.plugins.shared.utils import is_production
10-
from libsys_airflow.plugins.shared.utils import send_email_with_server_name
9+
from libsys_airflow.plugins.shared.utils import (
10+
is_production,
11+
send_email_with_server_name,
12+
)
1113

1214
logger = logging.getLogger(__name__)
1315

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

135137

138+
def _to_addresses():
139+
devs_to_email_addr = Variable.get("EMAIL_DEVS")
140+
bookplates_email_addr = Variable.get("BOOKPLATES_EMAIL")
141+
addresses = [devs_to_email_addr]
142+
if is_production():
143+
addresses.append(bookplates_email_addr)
144+
return addresses
145+
146+
136147
@task
137148
def bookplates_metadata_email(**kwargs):
138149
"""
@@ -165,7 +176,7 @@ def bookplates_metadata_email(**kwargs):
165176
)
166177

167178
send_email_with_server_name(
168-
to=to_addresses(),
179+
to=_to_addresses(),
169180
subject="Digital bookplates new and updated metadata",
170181
html_content=html_content,
171182
)
@@ -185,7 +196,7 @@ def deleted_from_argo_email(**kwargs):
185196
html_content = _deleted_from_argo_email_body(deleted_druids)
186197

187198
send_email_with_server_name(
188-
to=to_addresses(),
199+
to=_to_addresses(),
189200
subject="Deleted Druids from Argo for Digital bookplates",
190201
html_content=html_content,
191202
)
@@ -202,7 +213,7 @@ def missing_fields_email(**kwargs):
202213
html_content = _missing_fields_body(failures)
203214

204215
send_email_with_server_name(
205-
to=to_addresses(),
216+
to=_to_addresses(),
206217
subject="Missing Fields for Digital Bookplates",
207218
html_content=html_content,
208219
)
@@ -214,26 +225,15 @@ def missing_fields_email(**kwargs):
214225
def summary_add_979_dag_runs(**kwargs):
215226
dag_runs = kwargs["dag_runs"]
216227
additional_email = kwargs.get("email")
217-
218228
folio_url = Variable.get("FOLIO_URL")
219-
devs_to_email_addr = Variable.get("EMAIL_DEVS")
220229

221-
to_emails = [devs_to_email_addr]
230+
to_emails = _to_addresses()
222231
if additional_email:
223232
to_emails.append(additional_email)
224233
html_content = _summary_add_979_email(dag_runs, folio_url)
225234

226235
send_email_with_server_name(
227-
to=to_addresses(),
236+
to=to_emails,
228237
subject="Summary of Adding 979 fields to MARC Workflows",
229238
html_content=html_content,
230239
)
231-
232-
233-
def to_addresses():
234-
devs_to_email_addr = Variable.get("EMAIL_DEVS")
235-
bookplates_email_addr = Variable.get("BOOKPLATES_EMAIL")
236-
addresses = [devs_to_email_addr]
237-
if is_production():
238-
addresses.append(bookplates_email_addr)
239-
return addresses

libsys_airflow/plugins/shared/utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515

1616
def is_production():
17-
return bool(Variable.get("OKAPI_URL").find("prod") > 0)
17+
return Variable.get("OKAPI_URL").find("prod") > 0
1818

1919

2020
def send_email_with_server_name(**kwargs):

tests/digital_bookplates/test_bookplates_emails.py

Lines changed: 18 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,7 @@ def test_bookplates_metadata_email(
8181
mocker, mock_bookplate_metadata, mock_folio_variables
8282
):
8383

84-
mock_send_email = mocker.patch(
85-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name",
86-
)
84+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
8785

8886
bookplates_metadata_email.function(
8987
new=mock_bookplate_metadata["new"], updated=mock_bookplate_metadata["updated"]
@@ -121,9 +119,7 @@ def test_bookplates_metadata_email(
121119

122120

123121
def test_bookplates_metadata_email_none(mocker, mock_folio_variables, caplog):
124-
mock_send_email = mocker.patch(
125-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
126-
)
122+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
127123

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

@@ -138,9 +134,7 @@ def test_no_new_bookplates_metadata_email(
138134
mocker, mock_bookplate_metadata, mock_folio_variables, caplog
139135
):
140136

141-
mock_send_email = mocker.patch(
142-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
143-
)
137+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
144138

145139
bookplates_metadata_email.function(
146140
new=[], updated=mock_bookplate_metadata["updated"]
@@ -173,9 +167,7 @@ def test_no_updated_bookplates_metadata_email(
173167
mocker, mock_bookplate_metadata, mock_folio_variables, caplog
174168
):
175169

176-
mock_send_email = mocker.patch(
177-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
178-
)
170+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
179171

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

202194
def test_deleted_from_argo_email(mocker, mock_folio_variables):
203195

204-
mock_send_email = mocker.patch(
205-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
206-
)
196+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
207197

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

227217

228218
def test_deleted_from_argo_email_no_druids(mocker, caplog):
229-
mock_send_email = mocker.patch(
230-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
231-
)
219+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
232220

233221
deleted_from_argo_email.function(deleted_druids=[])
234222

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

238226

239227
def test_deleted_from_argo_email_prod(mocker, mock_folio_variables, caplog):
240-
mock_send_email = mocker.patch(
241-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
242-
)
228+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
243229

244230
mocker.patch(
245-
"libsys_airflow.plugins.digital_bookplates.email.is_production",
231+
"libsys_airflow.plugins.shared.utils.is_production",
246232
return_value=True,
247233
)
248234

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

255241

256242
def test_missing_fields_email(mocker, mock_folio_variables):
257-
mock_send_email = mocker.patch(
258-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
259-
)
243+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
260244

261245
missing_fields_email.function(failures=failures)
262246

@@ -284,12 +268,10 @@ def test_missing_fields_email_no_failures(mock_folio_variables, caplog):
284268

285269

286270
def test_missing_fields_email_prod(mocker, mock_folio_variables):
287-
mock_send_email = mocker.patch(
288-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
289-
)
271+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
290272

291273
mocker.patch(
292-
"libsys_airflow.plugins.digital_bookplates.email.is_production",
274+
"libsys_airflow.plugins.shared.utils.is_production",
293275
return_value=True,
294276
)
295277

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

302284

303285
def test_summary_add_979_dag_runs(mocker, mock_folio_variables):
304-
mock_send_email = mocker.patch(
305-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
306-
)
286+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
307287

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

358338

359339
def test_summary_add_979_dag_runs_prod(mocker, mock_folio_variables):
360-
mock_send_email = mocker.patch(
361-
"libsys_airflow.plugins.digital_bookplates.email.send_email_with_server_name"
340+
mock_send_email = mocker.patch("libsys_airflow.plugins.shared.utils.send_email")
341+
342+
mocker.patch(
343+
"libsys_airflow.plugins.shared.utils.is_production",
344+
return_value=True,
362345
)
363346

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

375358
assert mock_send_email.call_args[1]["to"] == [
376359
377-
378360
361+
379362
]

0 commit comments

Comments
 (0)