Skip to content

Commit

Permalink
Add standard email footer
Browse files Browse the repository at this point in the history
  • Loading branch information
kjsanger committed Nov 7, 2024
1 parent 1fbf787 commit cdf13c2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/npg_notify/data/resources/ont_event_email_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ $path
This is an automated email from NPG. You are receiving it because you are registered as a contact for one or more of the Studies listed below:

$studies

If you have any questions or need further assistance, please feel free to contact a Scientific Service Representative at dnap-ssr@$domain.

NPG on behalf of DNA Pipelines.
8 changes: 7 additions & 1 deletion src/npg_notify/ont/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,17 @@ def subject(self) -> str:
f"has been {self.event}"
)

def body(self, studies: list[Study]) -> str:
def body(self, studies: list[Study], domain: str = None) -> str:
"""Return the body of the email.
Args:
studies: The studies associated with the run.
domain: A network domain name to use when sending email. The main will
be sent from mail.<domain> with <user>@<domain> in the From: header.
"""
if domain is None:
raise ValueError("domain is required")

source = resources.files("npg_notify.data.resources").joinpath(
"ont_event_email_template.txt"
)
Expand All @@ -193,6 +198,7 @@ def body(self, studies: list[Study]) -> str:
"path": self.path,
"event": self.event,
"studies": "\n".join(study_descs),
"domain": domain,
}
)

Expand Down
8 changes: 7 additions & 1 deletion tests/ont/test_generate_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ def test_generate_email(self):
flowcell_id = "FAKE12345"
path = f"/testZone/home/irods/{expt}_{slot}_{flowcell_id}"
event_type = EventType.UPLOADED

domain = "no-such-domain.sanger.ac.uk"
studies = [Study(name="study1"), Study(name="study2")]

event = ContactEmail(
Expand All @@ -62,12 +64,16 @@ def test_generate_email(self):
study_descs = [f"{s.id_study_lims} ({s.name})" for s in studies]
study_lines = "\n".join(study_descs)

assert event.body(studies) == (
assert event.body(studies, domain=domain) == (
f"The ONT run for experiment {expt}, flowcell {flowcell_id} has been {event_type}. The data are available in iRODS at the following path:\n"
"\n"
f"{path}\n"
"\n"
"This is an automated email from NPG. You are receiving it because you are registered as a contact for one or more of the Studies listed below:\n"
"\n"
f"{study_lines}\n"
"\n"
f"If you have any questions or need further assistance, please feel free to contact a Scientific Service Representative at dnap-ssr@{domain}.\n"
"\n"
"NPG on behalf of DNA Pipelines.\n"
)

0 comments on commit cdf13c2

Please sign in to comment.