precommit

This commit is contained in:
jasquat 2022-08-04 14:28:50 -04:00
parent 4ef8ccea1e
commit 9f0acd3b3f
4 changed files with 27 additions and 13 deletions

View File

@ -1,9 +1,7 @@
"""Message_correlation_property."""
from sqlalchemy import ForeignKey
from flask_bpmn.models.db import db
from flask_bpmn.models.db import SpiffworkflowBaseDBModel
from sqlalchemy import ForeignKey
from spiffworkflow_backend.models.message_model import MessageModel

View File

@ -53,10 +53,12 @@ class MessageInstanceModel(SpiffworkflowBaseDBModel):
try:
m_type = getattr(enum_variable, value, None)
except Exception as e:
raise ValueError(f"{__class__.__name__}: invalid {key}: {value}") from e
raise ValueError(
f"{self.__class__.__name__}: invalid {key}: {value}"
) from e
if m_type is None:
raise ValueError(f"{__class__.__name__}: invalid {key}: {value}")
raise ValueError(f"{self.__class__.__name__}: invalid {key}: {value}")
return m_type.value
@ -76,7 +78,7 @@ class MessageInstanceModel(SpiffworkflowBaseDBModel):
#
# https://stackoverflow.com/questions/32555829/flask-validates-decorator-multiple-fields-simultaneously/33025472#33025472
# https://docs.sqlalchemy.org/en/14/orm/session_events.html#before-flush
@event.listens_for(Session, "before_flush")
@event.listens_for(Session, "before_flush") # type: ignore
def validate_and_modify_relationships(
session: Any, _flush_context: Optional[Any], _instances: Optional[Any]
) -> None:

View File

@ -35,7 +35,9 @@ class TestMessageInstance(BaseTest):
assert queued_message.status == "ready"
assert queued_message.failure_cause is None
queued_message_from_query = MessageInstanceModel.query.filter_by(id=queued_message.id).first()
queued_message_from_query = MessageInstanceModel.query.filter_by(
id=queued_message.id
).first()
assert queued_message_from_query is not None
def test_cannot_set_invalid_status(
@ -57,7 +59,9 @@ class TestMessageInstance(BaseTest):
message_model_id=message_model.id,
status="BAD_STATUS",
)
assert str(exception.value) == 'MessageInstanceModel: invalid status: BAD_STATUS'
assert (
str(exception.value) == "MessageInstanceModel: invalid status: BAD_STATUS"
)
queued_message = MessageInstanceModel(
process_instance_id=process_instance.id,
@ -70,7 +74,9 @@ class TestMessageInstance(BaseTest):
with pytest.raises(ValueError) as exception:
queued_message.status = "BAD_STATUS"
assert str(exception.value) == 'MessageInstanceModel: invalid status: BAD_STATUS'
assert (
str(exception.value) == "MessageInstanceModel: invalid status: BAD_STATUS"
)
def test_cannot_set_invalid_message_type(
self, app: Flask, with_db_and_bpmn_file_cleanup: None
@ -90,7 +96,10 @@ class TestMessageInstance(BaseTest):
message_type="BAD_MESSAGE_TYPE",
message_model_id=message_model.id,
)
assert str(exception.value) == 'MessageInstanceModel: invalid message_type: BAD_MESSAGE_TYPE'
assert (
str(exception.value)
== "MessageInstanceModel: invalid message_type: BAD_MESSAGE_TYPE"
)
queued_message = MessageInstanceModel(
process_instance_id=process_instance.id,
@ -103,7 +112,10 @@ class TestMessageInstance(BaseTest):
with pytest.raises(ValueError) as exception:
queued_message.message_type = "BAD_MESSAGE_TYPE"
assert str(exception.value) == 'MessageInstanceModel: invalid message_type: BAD_MESSAGE_TYPE'
assert (
str(exception.value)
== "MessageInstanceModel: invalid message_type: BAD_MESSAGE_TYPE"
)
def test_force_failure_cause_if_status_is_failure(
self, app: Flask, with_db_and_bpmn_file_cleanup: None
@ -126,7 +138,10 @@ class TestMessageInstance(BaseTest):
db.session.add(queued_message)
with pytest.raises(ValueError) as exception:
db.session.commit()
assert str(exception.value) == 'MessageInstanceModel: failure_cause must be set if status is failed'
assert (
str(exception.value)
== "MessageInstanceModel: failure_cause must be set if status is failed"
)
assert queued_message.id is None
db.session.remove()

View File

@ -7,7 +7,6 @@ from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
from spiffworkflow_backend.models.message_correlation import MessageCorrelationModel
from spiffworkflow_backend.models.message_instance import MessageInstanceModel
from spiffworkflow_backend.models.message_model import MessageModel
from spiffworkflow_backend.services.message_service import MessageService
class TestMessageService(BaseTest):