From fe54014107eb8a5c79e9baec069adccb98560496 Mon Sep 17 00:00:00 2001 From: jasquat Date: Mon, 31 Oct 2022 11:50:14 -0400 Subject: [PATCH] added script to get the frontend url w/ burnettk --- .../scripts/get_frontend_url.py | 25 +++++++++++++++ .../scripts/get_group_members.py | 8 +++-- .../scripts/test_get_group_members.py | 31 ++++++++++--------- 3 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_frontend_url.py diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_frontend_url.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_frontend_url.py new file mode 100644 index 00000000..40dc482c --- /dev/null +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_frontend_url.py @@ -0,0 +1,25 @@ +"""Get_env.""" +from typing import Any +from flask import current_app + +from spiffworkflow_backend.models.script_attributes_context import ( + ScriptAttributesContext, +) +from spiffworkflow_backend.scripts.script import Script + + +class GetFrontendUrl(Script): + """GetFrontendUrl.""" + + def get_description(self) -> str: + """Get_description.""" + return """Return the url to the frontend.""" + + def run( + self, + script_attributes_context: ScriptAttributesContext, + *args: Any, + **kwargs: Any + ) -> Any: + """Run.""" + return current_app.config['SPIFFWORKFLOW_FRONTEND_URL'] diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_group_members.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_group_members.py index 24abfeed..243a8c52 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_group_members.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_group_members.py @@ -1,7 +1,8 @@ """Get_env.""" from typing import Any -from spiffworkflow_backend.models.group import GroupModel, GroupNotFoundError +from spiffworkflow_backend.models.group import GroupModel +from spiffworkflow_backend.models.group import GroupNotFoundError from spiffworkflow_backend.models.script_attributes_context import ( ScriptAttributesContext, ) @@ -19,14 +20,15 @@ class GetGroupMembers(Script): self, script_attributes_context: ScriptAttributesContext, *args: Any, - **kwargs: Any + **kwargs: Any, ) -> Any: """Run.""" group_identifier = args[0] group = GroupModel.query.filter_by(identifier=group_identifier).first() if group is None: raise GroupNotFoundError( - f"Script 'get_group_members' could not find group with identifier '{group_identifier}'.") + f"Script 'get_group_members' could not find group with identifier '{group_identifier}'." + ) usernames = [u.username for u in group.users] return usernames diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_group_members.py b/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_group_members.py index ee6204a7..34a144db 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_group_members.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_group_members.py @@ -1,15 +1,14 @@ """Test_get_localtime.""" -from spiffworkflow_backend.services.user_service import UserService -from flask_bpmn.models.db import db -from spiffworkflow_backend.models.group import GroupModel - from flask.app import Flask +from flask_bpmn.models.db import db from tests.spiffworkflow_backend.helpers.base_test import BaseTest from tests.spiffworkflow_backend.helpers.test_data import load_test_spec +from spiffworkflow_backend.models.group import GroupModel from spiffworkflow_backend.services.process_instance_processor import ( ProcessInstanceProcessor, ) +from spiffworkflow_backend.services.user_service import UserService class TestGetGroupMembers(BaseTest): @@ -25,18 +24,19 @@ class TestGetGroupMembers(BaseTest): testuser1 = self.find_or_create_user("testuser1") testuser2 = self.find_or_create_user("testuser2") testuser3 = self.find_or_create_user("testuser3") - groupA = GroupModel(identifier="groupA") - groupB = GroupModel(identifier="groupB") - db.session.add(groupA) - db.session.add(groupB) + group_a = GroupModel(identifier="groupA") + group_b = GroupModel(identifier="groupB") + db.session.add(group_a) + db.session.add(group_b) db.session.commit() - UserService.add_user_to_group(testuser1, groupA) - UserService.add_user_to_group(testuser2, groupA) - UserService.add_user_to_group(testuser3, groupB) + UserService.add_user_to_group(testuser1, group_a) + UserService.add_user_to_group(testuser2, group_a) + UserService.add_user_to_group(testuser3, group_b) process_model = load_test_spec( - process_model_id="get_group_members", bpmn_file_name="get_group_members.bpmn" + process_model_id="get_group_members", + bpmn_file_name="get_group_members.bpmn", ) process_instance = self.create_process_instance_from_process_model( process_model=process_model, user=initiator_user @@ -45,5 +45,8 @@ class TestGetGroupMembers(BaseTest): processor.do_engine_steps(save=True) assert processor.bpmn_process_instance.data - assert processor.bpmn_process_instance.data['members_a'] == ['testuser1', 'testuser2'] - assert processor.bpmn_process_instance.data['members_b'] == ['testuser3'] + assert processor.bpmn_process_instance.data["members_a"] == [ + "testuser1", + "testuser2", + ] + assert processor.bpmn_process_instance.data["members_b"] == ["testuser3"]