|
7 | 7 | from galaxy.app_unittest_utils.tools_support import UsesApp |
8 | 8 | from galaxy.tools.errors import EmailErrorReporter |
9 | 9 | from galaxy.util.unittest import TestCase |
| 10 | +from galaxy.workflow.errors import WorkflowEmailErrorReporter |
10 | 11 |
|
11 | 12 | # The email the user created their account with. |
12 | 13 | TEST_USER_EMAIL = "mockgalaxyuser@galaxyproject.org" |
@@ -46,6 +47,38 @@ def test_basic(self): |
46 | 47 | assert "cat1" in email_json["html"] |
47 | 48 | assert TEST_USER_EMAIL == email_json["reply_to"] |
48 | 49 |
|
| 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 | + |
49 | 82 | def test_hda_security(self, tmp_path): |
50 | 83 | user, hda = self._setup_model_objects() |
51 | 84 | error_report = EmailErrorReporter(hda, self.app) |
@@ -137,6 +170,18 @@ def _setup_model_objects(self): |
137 | 170 | self._commit_objects([job, hda, user]) |
138 | 171 | return user, hda |
139 | 172 |
|
| 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 | + |
140 | 185 | def _commit_objects(self, objects): |
141 | 186 | session = self.app.model.context |
142 | 187 | session.add_all(objects) |
|
0 commit comments