diff --git a/migrations/env.py b/migrations/env.py index 630e381a..68feded2 100644 --- a/migrations/env.py +++ b/migrations/env.py @@ -1,3 +1,5 @@ +from __future__ import with_statement + import logging from logging.config import fileConfig diff --git a/migrations/versions/26094f78f273_.py b/migrations/versions/ae997451b037_.py similarity index 98% rename from migrations/versions/26094f78f273_.py rename to migrations/versions/ae997451b037_.py index 24b50686..bafb446f 100644 --- a/migrations/versions/26094f78f273_.py +++ b/migrations/versions/ae997451b037_.py @@ -1,8 +1,8 @@ """empty message -Revision ID: 26094f78f273 +Revision ID: ae997451b037 Revises: -Create Date: 2022-06-22 16:42:29.228683 +Create Date: 2022-06-24 13:47:56.423142 """ from alembic import op @@ -10,7 +10,7 @@ import sqlalchemy as sa # revision identifiers, used by Alembic. -revision = '26094f78f273' +revision = 'ae997451b037' down_revision = None branch_labels = None depends_on = None diff --git a/src/spiffworkflow_backend/__init__.py b/src/spiffworkflow_backend/__init__.py index 86158268..f0742172 100644 --- a/src/spiffworkflow_backend/__init__.py +++ b/src/spiffworkflow_backend/__init__.py @@ -14,6 +14,7 @@ from spiffworkflow_backend.routes.admin_blueprint.admin_blueprint import admin_b from spiffworkflow_backend.routes.api_blueprint import api_blueprint from spiffworkflow_backend.routes.process_api_blueprint import process_api_blueprint from spiffworkflow_backend.routes.user_blueprint import user_blueprint +from spiffworkflow_backend.services.acceptance_test_fixtures import load_fixtures def create_app() -> flask.app.Flask: @@ -55,4 +56,8 @@ def create_app() -> flask.app.Flask: connexion_app.add_api("api.yml", base_path="/v1.0") + if os.environ.get("SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA") == "true": + with app.app_context(): + load_fixtures() + return app # type: ignore diff --git a/src/spiffworkflow_backend/helpers/fixture_data.py b/src/spiffworkflow_backend/helpers/fixture_data.py new file mode 100644 index 00000000..0185f6d5 --- /dev/null +++ b/src/spiffworkflow_backend/helpers/fixture_data.py @@ -0,0 +1,15 @@ + +from typing import Any +from flask_bpmn.models.db import db +from spiffworkflow_backend.models.user import UserModel + + +def find_or_create_user(username: str = "test_user1") -> Any: + """Find_or_create_user.""" + user = UserModel.query.filter_by(username=username).first() + if user is None: + user = UserModel(username=username) + db.session.add(user) + db.session.commit() + + return user diff --git a/src/spiffworkflow_backend/models/process_instance.py b/src/spiffworkflow_backend/models/process_instance.py index 5a5bc4a5..88dc88fb 100644 --- a/src/spiffworkflow_backend/models/process_instance.py +++ b/src/spiffworkflow_backend/models/process_instance.py @@ -91,7 +91,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel): end_in_seconds: int | None = db.Column(db.Integer) # type: ignore updated_at_in_seconds: int = db.Column(db.Integer) # type: ignore created_at_in_seconds: int = db.Column(db.Integer) # type: ignore - status: str = db.Column(db.String()) # type: ignore + status: str = db.Column(db.String(50)) # type: ignore @property def serialized(self) -> dict[str, int | str | None]: diff --git a/src/spiffworkflow_backend/services/acceptance_test_fixtures.py b/src/spiffworkflow_backend/services/acceptance_test_fixtures.py index 821ed19b..20499377 100644 --- a/src/spiffworkflow_backend/services/acceptance_test_fixtures.py +++ b/src/spiffworkflow_backend/services/acceptance_test_fixtures.py @@ -3,7 +3,7 @@ import json import time from flask_bpmn.models.db import db -from tests.spiffworkflow_backend.helpers.test_data import find_or_create_user +from spiffworkflow_backend.helpers.fixture_data import find_or_create_user from spiffworkflow_backend.models.process_instance import ProcessInstanceModel from spiffworkflow_backend.models.process_instance import ProcessInstanceStatus @@ -17,16 +17,23 @@ def load_fixtures() -> list[ProcessInstanceModel]: statuses = ProcessInstanceStatus.list() current_time = round(time.time()) + # as of 2022-06-24 + # not_started - 1 hour ago + # user_input_required - 2 hours ago + # waiting - 3 hourse ago + # complete - 4 hours ago + # faulted - 5 hours ago + # suspended - 6 hours ago process_instances = [] - for i in range(5): + for i in range(len(statuses)): process_instance = ProcessInstanceModel( - status=ProcessInstanceStatus[statuses[i]], + status=statuses[i], process_initiator=user, process_model_identifier=test_process_model_id, process_group_identifier=test_process_group_id, updated_at_in_seconds=round(time.time()), - start_in_seconds=(3600 * i) + current_time, - end_in_seconds=(3600 * i + 20) + current_time, + start_in_seconds=current_time - (3600 * i), + end_in_seconds=current_time - (3600 * i - 20), bpmn_json=json.dumps({"i": i}), ) db.session.add(process_instance) diff --git a/tests/spiffworkflow_backend/helpers/test_data.py b/tests/spiffworkflow_backend/helpers/test_data.py index ea2c621d..9f1d70b2 100644 --- a/tests/spiffworkflow_backend/helpers/test_data.py +++ b/tests/spiffworkflow_backend/helpers/test_data.py @@ -15,17 +15,6 @@ from spiffworkflow_backend.models.user import UserModel from spiffworkflow_backend.services.process_model_service import ProcessModelService -def find_or_create_user(username: str = "test_user1") -> Any: - """Find_or_create_user.""" - user = UserModel.query.filter_by(username=username).first() - if user is None: - user = UserModel(username=username) - db.session.add(user) - db.session.commit() - - return user - - def assure_process_group_exists(process_group_id: Optional[str] = None) -> ProcessGroup: """Assure_process_group_exists.""" process_group = None diff --git a/tests/spiffworkflow_backend/integration/test_process_api.py b/tests/spiffworkflow_backend/integration/test_process_api.py index 1ba05afc..a988e217 100644 --- a/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/tests/spiffworkflow_backend/integration/test_process_api.py @@ -10,7 +10,7 @@ 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 find_or_create_user +from spiffworkflow_backend.helpers.fixture_data import find_or_create_user 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 diff --git a/tests/spiffworkflow_backend/unit/test_permissions.py b/tests/spiffworkflow_backend/unit/test_permissions.py index 6ea6ebd6..581ee8d1 100644 --- a/tests/spiffworkflow_backend/unit/test_permissions.py +++ b/tests/spiffworkflow_backend/unit/test_permissions.py @@ -1,7 +1,7 @@ """Test Permissions.""" from flask.app import Flask from flask_bpmn.models.db import db -from tests.spiffworkflow_backend.helpers.test_data import find_or_create_user +from spiffworkflow_backend.helpers.fixture_data import find_or_create_user from spiffworkflow_backend.models.principal import PrincipalModel diff --git a/wsgi.py b/wsgi.py index 69a30024..7144b1fe 100644 --- a/wsgi.py +++ b/wsgi.py @@ -1,11 +1,5 @@ """This is my docstring.""" -import os from spiffworkflow_backend import create_app -from spiffworkflow_backend.services.acceptance_test_fixtures import load_fixtures app = create_app() - -if os.environ.get("SPIFFWORKFLOW_BACKEND_LOAD_FIXTURE_DATA") == "true": - with app.app_context(): - load_fixtures()