Skip to content

Commit 38e3623

Browse files
add unit tests for invocation feedback reporting
1 parent 2012817 commit 38e3623

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

test/unit/app/tools/test_error_reporting.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from galaxy.app_unittest_utils.tools_support import UsesApp
88
from galaxy.tools.errors import EmailErrorReporter
99
from galaxy.util.unittest import TestCase
10+
from galaxy.workflow.errors import WorkflowEmailErrorReporter
1011

1112
# The email the user created their account with.
1213
TEST_USER_EMAIL = "mockgalaxyuser@galaxyproject.org"
@@ -46,6 +47,38 @@ def test_basic(self):
4647
assert "cat1" in email_json["html"]
4748
assert TEST_USER_EMAIL == email_json["reply_to"]
4849

50+
def test_workflow_error_reporting(self):
51+
user, invocation = self._setup_invocation_model_objects()
52+
53+
email_path = self.email_path
54+
assert not email_path.exists()
55+
error_report = WorkflowEmailErrorReporter(invocation, self.app)
56+
error_report.send_report(user, email=TEST_USER_SUPPLIED_EMAIL, message="My custom message")
57+
assert email_path.exists()
58+
text = email_path.read_text()
59+
email_json = json.loads(text)
60+
assert email_json["from"] == TEST_SERVER_EMAIL_FROM
61+
assert email_json["to"] == f"{TEST_SERVER_ERROR_EMAIL_TO}, {TEST_USER_SUPPLIED_EMAIL}"
62+
assert f"Galaxy workflow run error report from {TEST_USER_SUPPLIED_EMAIL}" == email_json["subject"]
63+
assert "Test Workflow" in email_json["body"]
64+
assert "Test Workflow" in email_json["html"]
65+
assert TEST_USER_EMAIL == email_json["reply_to"]
66+
67+
def test_workflow_error_reporting_unowned_history(self):
68+
_, invocation = self._setup_invocation_model_objects()
69+
other_user = model.User(email="otheruser@galaxyproject.org", password="mockpass2")
70+
self._commit_objects([other_user])
71+
72+
email_path = self.email_path
73+
assert not email_path.exists()
74+
error_report = WorkflowEmailErrorReporter(invocation, self.app)
75+
error_report.send_report(other_user, email=TEST_USER_SUPPLIED_EMAIL, message="My custom message")
76+
assert email_path.exists()
77+
text = email_path.read_text()
78+
email_json = json.loads(text)
79+
assert email_json["from"] == TEST_SERVER_EMAIL_FROM
80+
assert email_json["to"] == f"{TEST_SERVER_ERROR_EMAIL_TO}"
81+
4982
def test_hda_security(self, tmp_path):
5083
user, hda = self._setup_model_objects()
5184
error_report = EmailErrorReporter(hda, self.app)
@@ -137,6 +170,18 @@ def _setup_model_objects(self):
137170
self._commit_objects([job, hda, user])
138171
return user, hda
139172

173+
def _setup_invocation_model_objects(self):
174+
user = model.User(email=TEST_USER_EMAIL, password="mockpass")
175+
invocation = model.WorkflowInvocation()
176+
invocation.workflow = model.Workflow()
177+
invocation.workflow.name = "Test Workflow"
178+
invocation.workflow.stored_workflow = model.StoredWorkflow()
179+
invocation.workflow.stored_workflow.user = user
180+
invocation.history = model.History()
181+
invocation.history.user = user
182+
self._commit_objects([user, invocation])
183+
return user, invocation
184+
140185
def _commit_objects(self, objects):
141186
session = self.app.model.context
142187
session.add_all(objects)

0 commit comments

Comments
 (0)