From 2c3b88042ef3327dee2ce517810628976b71e608 Mon Sep 17 00:00:00 2001 From: burnettk Date: Mon, 6 Feb 2023 10:30:38 -0500 Subject: [PATCH] move towards returning dict in get_current_user --- .../scripts/get_current_user.py | 2 +- .../scripts/test_get_current_user.py | 44 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_current_user.py diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_current_user.py b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_current_user.py index e4b524c2a..53ebd1c5b 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_current_user.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/scripts/get_current_user.py @@ -26,4 +26,4 @@ class GetCurrentUser(Script): **kwargs: Any ) -> Any: """Run.""" - return g.user.username + return g.user.__dict__ diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_current_user.py b/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_current_user.py new file mode 100644 index 000000000..146baaf65 --- /dev/null +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/scripts/test_get_current_user.py @@ -0,0 +1,44 @@ +"""Test_get_localtime.""" +from flask.app import Flask +from flask import g +from flask.testing import FlaskClient +from spiffworkflow_backend.models.script_attributes_context import ScriptAttributesContext +from spiffworkflow_backend.scripts.get_current_user import GetCurrentUser +from tests.spiffworkflow_backend.helpers.base_test import BaseTest +from tests.spiffworkflow_backend.helpers.test_data import load_test_spec + +from spiffworkflow_backend.models.db import db +from spiffworkflow_backend.models.group import GroupModel +from spiffworkflow_backend.models.user import UserModel +from spiffworkflow_backend.services.process_instance_processor import ( + ProcessInstanceProcessor, +) +from spiffworkflow_backend.services.user_service import UserService + + +class TestGetCurrentUser(BaseTest): + + def test_get_current_user( + self, + app: Flask, + client: FlaskClient, + with_db_and_bpmn_file_cleanup: None, + with_super_admin_user: UserModel, + ) -> None: + """Test_can_get_members_of_a_group.""" + testuser1 = self.find_or_create_user("testuser1") + testuser1.tenant_specific_field_1 = "456" + db.session.add(testuser1) + g.user = testuser1 + process_model_identifier = "test_process_model" + process_instance_id = 1 + script_attributes_context = ScriptAttributesContext( + task=None, + environment_identifier="testing", + process_instance_id=process_instance_id, + process_model_identifier=process_model_identifier, + ) + result = GetCurrentUser().run( + script_attributes_context, + ) + assert result['username'] == "testuser1"