fixed some precommit

This commit is contained in:
jasquat 2022-06-20 10:56:32 -04:00
parent 5cfe999d34
commit 65da9ccbaa
15 changed files with 112 additions and 61 deletions

View File

@ -1,23 +1,27 @@
"""Grabs tickets from csv and makes process instances."""
import csv
import os
from flask import current_app
from flask_bpmn.models.db import db
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
import csv
from spiffworkflow_backend import create_app
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService
from flask import current_app
from spiffworkflow_backend.services.process_instance_processor import (
ProcessInstanceProcessor,
)
from spiffworkflow_backend.services.process_instance_service import (
ProcessInstanceService,
)
from spiffworkflow_backend.services.process_model_service import ProcessModelService
def print_process_instance_count(process_model_identifier_ticket: str) -> None:
"""Print process instance count."""
process_instances = ProcessInstanceModel.query.filter_by(process_model_identifier=process_model_identifier_ticket).all()
process_instances = ProcessInstanceModel.query.filter_by(
process_model_identifier=process_model_identifier_ticket
).all()
process_instance_count = len(process_instances)
print(f"process_instance_count: {process_instance_count}")
@ -30,19 +34,31 @@ def main():
with app.app_context():
process_model_identifier_ticket = "ticket"
db.session.query(ProcessInstanceModel).filter(ProcessInstanceModel.process_model_identifier == process_model_identifier_ticket).delete()
db.session.query(ProcessInstanceModel).filter(
ProcessInstanceModel.process_model_identifier
== process_model_identifier_ticket
).delete()
db.session.commit()
"""Print process instance count."""
process_instances = ProcessInstanceModel.query.filter_by(process_model_identifier=process_model_identifier_ticket).all()
process_instances = ProcessInstanceModel.query.filter_by(
process_model_identifier=process_model_identifier_ticket
).all()
process_instance_count = len(process_instances)
print(f"process_instance_count: {process_instance_count}")
# process_model = ProcessModelService().get_process_model(process_model_identifier_ticket)
columns_to_data_key_mappings = {"Month": "month", "MS": "milestone", "ID": "req_id", "Dev Days": "dev_days", "Feature": "feature", "Priority": "priority"}
columns_to_data_key_mappings = {
"Month": "month",
"MS": "milestone",
"ID": "req_id",
"Dev Days": "dev_days",
"Feature": "feature",
"Priority": "priority",
}
columns_to_header_index_mappings = {}
user = UserModel.query.filter_by(username='test_user1').first()
user = UserModel.query.filter_by(username="test_user1").first()
with open("tests/files/tickets.csv") as infile:
reader = csv.reader(infile, delimiter=",")
@ -52,7 +68,9 @@ def main():
header = next(reader)
for column_name in columns_to_data_key_mappings:
columns_to_header_index_mappings[column_name] = header.index(column_name)
columns_to_header_index_mappings[column_name] = header.index(
column_name
)
id_index = header.index("ID")
priority_index = header.index("Priority")
print(f"header: {header}")
@ -70,9 +88,14 @@ def main():
processor.do_engine_steps()
# processor.save()
for column_name, desired_data_key in columns_to_data_key_mappings.items():
for (
column_name,
desired_data_key,
) in columns_to_data_key_mappings.items():
appropriate_index = columns_to_header_index_mappings[column_name]
processor.bpmn_process_instance.data[desired_data_key] = row[appropriate_index]
processor.bpmn_process_instance.data[desired_data_key] = row[
appropriate_index
]
print(f"datas: {processor.bpmn_process_instance.data}")
if processor.bpmn_process_instance.data["month"] == "":
@ -85,6 +108,5 @@ def main():
processor.save()
# if __name__ == "__main__":
main()

View File

@ -1,33 +1,46 @@
import csv
import os
from flask import current_app
from flask_bpmn.models.db import db
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
import csv
from spiffworkflow_backend import create_app
from spiffworkflow_backend.models.process_instance import ProcessInstanceModel
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.process_instance_processor import ProcessInstanceProcessor
from spiffworkflow_backend.services.process_instance_service import ProcessInstanceService
from flask import current_app
from spiffworkflow_backend.services.process_instance_processor import (
ProcessInstanceProcessor,
)
from spiffworkflow_backend.services.process_instance_service import (
ProcessInstanceService,
)
from spiffworkflow_backend.services.process_model_service import ProcessModelService
process_model_identifier_ticket = "ticket"
db.session.query(ProcessInstanceModel).filter(ProcessInstanceModel.process_model_identifier == process_model_identifier_ticket).delete()
db.session.query(ProcessInstanceModel).filter(
ProcessInstanceModel.process_model_identifier == process_model_identifier_ticket
).delete()
db.session.commit()
"""Print process instance count."""
process_instances = ProcessInstanceModel.query.filter_by(process_model_identifier=process_model_identifier_ticket).all()
process_instances = ProcessInstanceModel.query.filter_by(
process_model_identifier=process_model_identifier_ticket
).all()
process_instance_count = len(process_instances)
print(f"process_instance_count: {process_instance_count}")
process_model = ProcessModelService().get_process_model(process_model_identifier_ticket)
columns_to_data_key_mappings = {"Month": "month", "MS": "milestone", "ID": "req_id", "Dev Days": "dev_days", "Feature": "feature", "Priority": "priority"}
columns_to_data_key_mappings = {
"Month": "month",
"MS": "milestone",
"ID": "req_id",
"Dev Days": "dev_days",
"Feature": "feature",
"Priority": "priority",
}
columns_to_header_index_mappings = {}
user = UserModel.query.filter_by(username='test_user1').first()
user = UserModel.query.filter_by(username="test_user1").first()
with open("tests/files/tickets.csv") as infile:
reader = csv.reader(infile, delimiter=",")
@ -58,7 +71,9 @@ with open("tests/files/tickets.csv") as infile:
for column_name, desired_data_key in columns_to_data_key_mappings.items():
appropriate_index = columns_to_header_index_mappings[column_name]
print(f"appropriate_index: {appropriate_index}")
processor.bpmn_process_instance.data[desired_data_key] = row[appropriate_index]
processor.bpmn_process_instance.data[desired_data_key] = row[
appropriate_index
]
# you at least need a month, or else this row in the csv is considered garbage
month_value = processor.bpmn_process_instance.data["month"]

View File

@ -1,5 +1,3 @@
from __future__ import with_statement
import logging
from logging.config import fileConfig

View File

@ -1,12 +1,12 @@
"""Process_group."""
import marshmallow
from marshmallow import post_load
from marshmallow import Schema
from dataclasses import dataclass
from dataclasses import field
from typing import Optional
import marshmallow
from marshmallow import post_load
from marshmallow import Schema
from spiffworkflow_backend.models.process_model import ProcessModelInfo

View File

@ -1,5 +1,4 @@
"""Process_instance."""
from flask_bpmn.models.db import db
from sqlalchemy import ForeignKey
from sqlalchemy import func

View File

@ -1,12 +1,12 @@
"""Process_model."""
import marshmallow
from marshmallow import post_load
from marshmallow import Schema
from dataclasses import dataclass
from dataclasses import field
from typing import Optional
import marshmallow
from marshmallow import post_load
from marshmallow import Schema
@dataclass(order=True)
class ProcessModelInfo:

View File

@ -1,5 +1,6 @@
"""User."""
from typing import Optional
import jwt
import marshmallow
from flask import current_app
@ -66,9 +67,7 @@ class UserModel(db.Model): # type: ignore
raise KeyError("we need current_app.config to have a SECRET_KEY")
try:
payload = jwt.decode(
auth_token, secret_key, algorithms=["HS256"]
)
payload = jwt.decode(auth_token, secret_key, algorithms=["HS256"])
return payload
except jwt.ExpiredSignatureError as exception:
raise ApiError(

View File

@ -160,7 +160,9 @@ def process_model_list(process_group_id, page=1, per_page=100):
def get_file(process_group_id, process_model_id, file_name):
"""Get_file."""
process_model = ProcessModelService().get_process_model(process_model_id, group_id=process_group_id)
process_model = ProcessModelService().get_process_model(
process_model_id, group_id=process_group_id
)
files = SpecFileService.get_files(process_model, file_name)
if len(files) == 0:
raise ApiError(
@ -180,7 +182,9 @@ def get_file(process_group_id, process_model_id, file_name):
def process_model_file_update(process_group_id, process_model_id, file_name):
"""Process_model_file_save."""
process_model = ProcessModelService().get_process_model(process_model_id, group_id=process_group_id)
process_model = ProcessModelService().get_process_model(
process_model_id, group_id=process_group_id
)
request_file = get_file_from_request()
request_file_contents = request_file.stream.read()
@ -198,7 +202,9 @@ def process_model_file_update(process_group_id, process_model_id, file_name):
def add_file(process_group_id, process_model_id):
"""Add_file."""
process_model_service = ProcessModelService()
process_model = process_model_service.get_process_model(process_model_id, group_id=process_group_id)
process_model = process_model_service.get_process_model(
process_model_id, group_id=process_group_id
)
request_file = get_file_from_request()
file = SpecFileService.add_file(
process_model, request_file.filename, request_file.stream.read()
@ -239,7 +245,9 @@ def process_instance_create(process_group_id, process_model_id):
def process_instance_list(process_group_id, process_model_id, page=1, per_page=100):
"""Process_instance_list."""
process_model = ProcessModelService().get_process_model(process_model_id, group_id=process_group_id)
process_model = ProcessModelService().get_process_model(
process_model_id, group_id=process_group_id
)
if process_model is None:
raise (
ApiError(
@ -276,7 +284,9 @@ def process_instance_list(process_group_id, process_model_id, page=1, per_page=1
def process_instance_report(process_group_id, process_model_id, page=1, per_page=100):
"""Process_instance_list."""
process_model = ProcessModelService().get_process_model(process_model_id, group_id=process_group_id)
process_model = ProcessModelService().get_process_model(
process_model_id, group_id=process_group_id
)
if process_model is None:
raise (
ApiError(

View File

@ -49,6 +49,7 @@ class Script:
We may be able to remove the task for each of these calls if we are not using it other than potentially
updating the task data.
"""
def make_closure(subclass, task, workflow_id):
"""Yes - this is black magic.
@ -84,6 +85,7 @@ class Script:
We may be able to remove the task for each of these calls if we are not using it other than potentially
updating the task data.
"""
def make_closure_validate(subclass, task, workflow_id):
"""Make_closure_validate."""
instance = subclass()

View File

@ -28,7 +28,9 @@ class ProcessInstanceService:
TASK_STATE_LOCKED = "locked"
@staticmethod
def create_process_instance(process_model_identifier, user, process_group_identifier=None):
def create_process_instance(
process_model_identifier, user, process_group_identifier=None
):
"""Get_process_instance_from_spec."""
process_instance_model = ProcessInstanceModel(
status=ProcessInstanceStatus.not_started,

View File

@ -2,7 +2,8 @@
import os
import shutil
from datetime import datetime
from typing import List, Union
from typing import List
from typing import Union
from flask_bpmn.api.api_error import ApiError
from lxml import etree # type: ignore
@ -126,7 +127,9 @@ class SpecFileService(FileSystemService):
@staticmethod
def set_primary_bpmn(
workflow_spec: ProcessModelInfo, file_name: str, binary_data: Union[bytes, None] = None
workflow_spec: ProcessModelInfo,
file_name: str,
binary_data: Union[bytes, None] = None,
) -> None:
"""Set_primary_bpmn."""
# If this is a BPMN, extract the process id, and determine if it is contains swim lanes.

View File

@ -1,5 +1,4 @@
"""Test Api Blueprint."""
# TODO: possibly get this test working again
# import json
# from typing import Union

View File

@ -689,7 +689,7 @@ def test_process_instance_report_with_default_list(
<= process_instance_dict["end_in_seconds"]
)
assert process_instance_dict["status"] == "complete"
assert process_instance_dict["data"]['Mike'] == "Awesome"
assert process_instance_dict["data"]["Mike"] == "Awesome"
def create_process_instance(

View File

@ -4,7 +4,9 @@ from spiffworkflow_backend.models.process_model import ProcessModelInfo
def test_initializes_files_as_empty_array() -> None:
"""Test_initializes_files_as_empty_array."""
process_model_one = create_test_process_model(id="model_one", display_name="Model One")
process_model_one = create_test_process_model(
id="model_one", display_name="Model One"
)
assert process_model_one.files == []
assert process_model_one.libraries == []