Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subject line for production vs other and refactor tests #1399

Merged
merged 3 commits into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion libsys_airflow/plugins/folio/encumbrances/email.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import re

from airflow.models import Variable
from airflow.utils.email import send_email
from jinja2 import Template

from libsys_airflow.plugins.shared.utils import is_production


def email_log(**kwargs):
library = kwargs.get("library", "")
Expand All @@ -26,7 +30,7 @@ def email_log(**kwargs):
with open(log_file, 'r') as fo:
send_email(
to=to_addresses,
subject=f"Fix Encumbrances for {library}",
subject=subject(library=library),
html_content=_email_body(fo),
)

Expand All @@ -40,3 +44,13 @@ def _email_body(log):
html_body = email_template.render(log_content=log.read())

return html_body


def subject(**kwargs):
library = kwargs.get("library", "")
folio_url = Variable.get("FOLIO_URL", "Test or Stage")
if is_production():
return f"Fix Encumbrances for {library}"
else:
folio_url = re.sub('http?://', '', folio_url)
return f"{folio_url} - Fix Encumbrances for {library}"
16 changes: 10 additions & 6 deletions tests/test_fix_encumbrances_run.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import pytest

from unittest.mock import AsyncMock

from airflow.models import Variable

from unittest.mock import AsyncMock


@pytest.fixture
def mock_task_instance(mocker):
Expand All @@ -21,10 +21,6 @@ def mock_get(*args):
monkeypatch.setattr(Variable, "get", mock_get)


def reset_mock_okapi(monkeypatch):
monkeypatch.delenv('OKAPI_URL', raising=False)


def test_fix_encumbrances_log_file_params(
mocker, tmp_path, mock_task_instance, mock_okapi, monkeypatch
):
Expand All @@ -39,6 +35,7 @@ def test_fix_encumbrances_log_file_params(
side_effect=async_mock,
return_value=None,
)

from libsys_airflow.plugins.folio.encumbrances.fix_encumbrances_run import (
fix_encumbrances_run,
)
Expand All @@ -55,3 +52,10 @@ def test_fix_encumbrances_log_file_params(
)

assert log_path.endswith("foo-scheduled__2024-07-29T19:00:00:00:00.log")


def test_fix_encumbrances_email_subject():
from libsys_airflow.plugins.folio.encumbrances.email import subject

subj = subject(library="SUL2024")
assert subj == "okapi-test - Fix Encumbrances for SUL2024"
Loading