added fixture data helper and some other changes related to acceptance tests w/ burnettk
This commit is contained in:
parent
b80d1b2823
commit
6641b9c6d4
|
@ -1,3 +1,5 @@
|
|||
from __future__ import with_statement
|
||||
|
||||
import logging
|
||||
from logging.config import fileConfig
|
||||
|
||||
|
|
|
@ -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
|
|
@ -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
|
||||
|
|
|
@ -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
|
|
@ -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]:
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
6
wsgi.py
6
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()
|
||||
|
|
Loading…
Reference in New Issue