Use BaseTest in test_process_api

Move base_test into helpers directory
Move find_or_create_user to BaseTest
This commit is contained in:
mike cullerton 2022-08-02 10:46:53 -04:00
parent 0bd3503608
commit 4219ce6ced
5 changed files with 1227 additions and 1234 deletions

View File

@ -7,8 +7,8 @@ from flask.app import Flask
from flask_bpmn.models.db import db from flask_bpmn.models.db import db
from flask_bpmn.models.db import SpiffworkflowBaseDBModel from flask_bpmn.models.db import SpiffworkflowBaseDBModel
from tests.spiffworkflow_backend.helpers.test_data import load_test_spec from tests.spiffworkflow_backend.helpers.test_data import load_test_spec
from tests.spiffworkflow_backend.helpers.base_test import BaseTest
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 ProcessInstanceModel
from spiffworkflow_backend.services.process_instance_processor import ( from spiffworkflow_backend.services.process_instance_processor import (
ProcessInstanceProcessor, ProcessInstanceProcessor,
@ -65,7 +65,7 @@ def with_db_and_bpmn_file_cleanup() -> None:
@pytest.fixture() @pytest.fixture()
def setup_process_instances_for_reports() -> list[ProcessInstanceModel]: def setup_process_instances_for_reports() -> list[ProcessInstanceModel]:
"""Setup_process_instances_for_reports.""" """Setup_process_instances_for_reports."""
user = find_or_create_user() user = BaseTest.find_or_create_user()
process_group_id = "runs_without_input" process_group_id = "runs_without_input"
process_model_id = "sample" process_model_id = "sample"
load_test_spec(process_group_id=process_group_id, process_model_id=process_model_id) load_test_spec(process_group_id=process_group_id, process_model_id=process_model_id)

View File

@ -1,16 +1 @@
"""Fixture_data.""" """Fixture_data."""
from typing import Any
from spiffworkflow_backend.models.user import UserModel
from spiffworkflow_backend.services.user_service import UserService
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 = UserService().create_user("local", username, username=username)
UserService().create_principal(user_id=user.id)
return user

View File

@ -1,14 +1,27 @@
"""Base_test.""" """Base_test."""
from flask.app import Flask from flask.app import Flask
from spiffworkflow_backend.services.authentication_service import ( from spiffworkflow_backend.models.user import UserModel
PublicAuthenticationService, from spiffworkflow_backend.services.user_service import UserService
) from spiffworkflow_backend.services.authentication_service import PublicAuthenticationService
class BaseTest: class BaseTest:
"""BaseTest.""" """BaseTest."""
@staticmethod
def find_or_create_user(username: str = "test_user1") -> UserModel:
"""Find_or_create_user."""
user = UserModel.query.filter_by(username=username).first()
if isinstance(user, UserModel):
return user
else:
user: UserModel = UserService().create_user("local", username, username=username)
UserService().create_principal(user_id=user.id)
return user
@staticmethod @staticmethod
def get_keycloak_constants(app: Flask) -> tuple: def get_keycloak_constants(app: Flask) -> tuple:
"""Get_keycloak_constants.""" """Get_keycloak_constants."""

View File

@ -1,5 +1,5 @@
"""Test_authorization.""" """Test_authorization."""
from tests.spiffworkflow_backend.integration.base_test import BaseTest from tests.spiffworkflow_backend.helpers.base_test import BaseTest
class TestAuthorization(BaseTest): class TestAuthorization(BaseTest):

File diff suppressed because it is too large Load Diff