run pre commit
This commit is contained in:
parent
77227c545a
commit
d21ad20525
|
@ -9,7 +9,6 @@ from flask_bpmn.models.db import migrate
|
|||
from flask_cors import CORS # type: ignore
|
||||
from flask_mail import Mail
|
||||
|
||||
|
||||
import spiffworkflow_backend.load_database_models # noqa: F401
|
||||
from spiffworkflow_backend.config import setup_config
|
||||
from spiffworkflow_backend.routes.admin_blueprint.admin_blueprint import admin_blueprint
|
||||
|
|
|
@ -1,30 +1,45 @@
|
|||
"""Email_service."""
|
||||
from flask import current_app
|
||||
from flask_mail import Message
|
||||
|
||||
|
||||
class EmailService(object):
|
||||
"""Provides common interface for working with an Email"""
|
||||
class EmailService:
|
||||
"""Provides common interface for working with an Email."""
|
||||
|
||||
@staticmethod
|
||||
def add_email(subject, sender, recipients, content, content_html,
|
||||
cc=None, bcc=None, study_id=None, reply_to=None, attachment_files=None, workflow_spec_id=None, name=None):
|
||||
"""We will receive all data related to an email and send it"""
|
||||
def add_email(
|
||||
subject,
|
||||
sender,
|
||||
recipients,
|
||||
content,
|
||||
content_html,
|
||||
cc=None,
|
||||
bcc=None,
|
||||
study_id=None,
|
||||
reply_to=None,
|
||||
attachment_files=None,
|
||||
workflow_spec_id=None,
|
||||
name=None,
|
||||
):
|
||||
"""We will receive all data related to an email and send it."""
|
||||
mail = current_app.config["MAIL_APP"]
|
||||
|
||||
# Send mail
|
||||
try:
|
||||
msg = Message(subject,
|
||||
sender=sender,
|
||||
recipients=recipients,
|
||||
body=content,
|
||||
html=content_html,
|
||||
cc=cc,
|
||||
bcc=bcc,
|
||||
reply_to=reply_to)
|
||||
msg = Message(
|
||||
subject,
|
||||
sender=sender,
|
||||
recipients=recipients,
|
||||
body=content,
|
||||
html=content_html,
|
||||
cc=cc,
|
||||
bcc=bcc,
|
||||
reply_to=reply_to,
|
||||
)
|
||||
|
||||
if attachment_files is not None:
|
||||
for file in attachment_files:
|
||||
msg.attach(file['name'], file['type'], file['data'])
|
||||
msg.attach(file["name"], file["type"], file["data"])
|
||||
|
||||
mail.send(msg)
|
||||
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
"""Error_handling_service."""
|
||||
from typing import Union
|
||||
|
||||
from flask import current_app
|
||||
from flask_bpmn.api.api_error import ApiError
|
||||
from flask_bpmn.models.db import db
|
||||
|
||||
|
@ -51,45 +50,41 @@ class ErrorHandlingService:
|
|||
if len(process_model.exception_notification_addresses) > 0:
|
||||
try:
|
||||
# some notification method (waku?)
|
||||
self.handle_email_notification(_processor, _error, process_model.exception_notification_addresses)
|
||||
self.handle_email_notification(
|
||||
_processor, _error, process_model.exception_notification_addresses
|
||||
)
|
||||
except Exception as e:
|
||||
# hmm... what to do if a notification method fails. Probably log, at least
|
||||
print(e)
|
||||
print(f"handle_error: {_error}")
|
||||
|
||||
|
||||
@staticmethod
|
||||
def hanle_sentry_notification(_error, _recipients):
|
||||
"""SentryHandler."""
|
||||
|
||||
...
|
||||
|
||||
|
||||
@staticmethod
|
||||
def handle_email_notification(processor, error, recipients):
|
||||
"""EmailHandler."""
|
||||
|
||||
subject = f"Unexpected error in app"
|
||||
subject = "Unexpected error in app"
|
||||
content = f"{error.message}"
|
||||
content_html = content
|
||||
|
||||
EmailService.add_email(
|
||||
subject,
|
||||
'sender@company.com',
|
||||
"sender@company.com",
|
||||
recipients,
|
||||
content,
|
||||
content_html,
|
||||
cc=None,
|
||||
bcc=None,
|
||||
reply_to=None,
|
||||
attachment_files=None
|
||||
attachment_files=None,
|
||||
)
|
||||
|
||||
|
||||
@staticmethod
|
||||
def handle_waku_notification(_error, _recipients):
|
||||
"""WakuHandler."""
|
||||
|
||||
...
|
||||
|
||||
|
||||
|
|
|
@ -10,7 +10,6 @@ import pytest
|
|||
from flask.app import Flask
|
||||
from flask.testing import FlaskClient
|
||||
from flask_bpmn.models.db import db
|
||||
|
||||
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
|
||||
from tests.spiffworkflow_backend.helpers.test_data import logged_in_headers
|
||||
from werkzeug.test import TestResponse
|
||||
|
@ -822,7 +821,7 @@ def test_process_instance_report_with_default_list(
|
|||
|
||||
|
||||
def setup_testing_instance(client, process_group_id, process_model_id, user):
|
||||
|
||||
"""Setup_testing_instance."""
|
||||
headers = logged_in_headers(user)
|
||||
response = create_process_instance(
|
||||
client, process_group_id, process_model_id, headers
|
||||
|
@ -842,7 +841,9 @@ def test_error_handler(
|
|||
process_model_id = "error"
|
||||
user = find_or_create_user()
|
||||
|
||||
process_instance_id = setup_testing_instance(client, process_group_id, process_model_id, user)
|
||||
process_instance_id = setup_testing_instance(
|
||||
client, process_group_id, process_model_id, user
|
||||
)
|
||||
process = (
|
||||
db.session.query(ProcessInstanceModel)
|
||||
.filter(ProcessInstanceModel.id == process_instance_id)
|
||||
|
@ -885,10 +886,16 @@ def test_error_handler_with_email(
|
|||
process_model_id = "error"
|
||||
user = find_or_create_user()
|
||||
|
||||
process_instance_id = setup_testing_instance(client, process_group_id, process_model_id, user)
|
||||
process_instance_id = setup_testing_instance(
|
||||
client, process_group_id, process_model_id, user
|
||||
)
|
||||
|
||||
process_model = ProcessModelService().get_process_model(process_model_id, process_group_id)
|
||||
process_model.exception_notification_addresses = ['user@example.com',]
|
||||
process_model = ProcessModelService().get_process_model(
|
||||
process_model_id, process_group_id
|
||||
)
|
||||
process_model.exception_notification_addresses = [
|
||||
"user@example.com",
|
||||
]
|
||||
ProcessModelService().update_spec(process_model)
|
||||
|
||||
mail = app.config["MAIL_APP"]
|
||||
|
@ -901,8 +908,11 @@ def test_error_handler_with_email(
|
|||
assert response.status_code == 400
|
||||
assert len(outbox) == 1
|
||||
message = outbox[0]
|
||||
assert message.subject == 'Unexpected error in app'
|
||||
assert message.body == 'Activity_CauseError: TypeError:can only concatenate str (not "int") to str'
|
||||
assert message.subject == "Unexpected error in app"
|
||||
assert (
|
||||
message.body
|
||||
== 'Activity_CauseError: TypeError:can only concatenate str (not "int") to str'
|
||||
)
|
||||
assert message.recipients == process_model.exception_notification_addresses
|
||||
|
||||
process = (
|
||||
|
@ -985,9 +995,9 @@ def create_process_model(
|
|||
if exception_notification_addresses is None:
|
||||
exception_notification_addresses = []
|
||||
if primary_process_id is None:
|
||||
primary_process_id = ''
|
||||
primary_process_id = ""
|
||||
if primary_file_name is None:
|
||||
primary_file_name = ''
|
||||
primary_file_name = ""
|
||||
model = ProcessModelInfo(
|
||||
id=process_model_id,
|
||||
display_name=process_model_display_name,
|
||||
|
|
Loading…
Reference in New Issue