From aa8985f3aab8ab56db823fcd31febc3d355028fa Mon Sep 17 00:00:00 2001 From: jasquat Date: Wed, 4 Jan 2023 16:15:15 -0500 Subject: [PATCH] pyl --- .../models/human_task.py | 4 +-- .../models/human_task_user.py | 2 +- .../spiffworkflow_backend/models/principal.py | 2 +- .../models/process_instance.py | 2 +- .../models/process_instance_report.py | 2 +- .../models/secret_model.py | 2 +- .../src/spiffworkflow_backend/models/user.py | 4 +-- .../models/user_group_assignment.py | 2 +- .../routes/tasks_controller.py | 2 +- .../routes/users_controller.py | 10 +++--- .../integration/test_users_controller.py | 34 +++++++++++-------- 11 files changed, 35 insertions(+), 31 deletions(-) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py index 940a51fc..f74da5cc 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task.py @@ -35,9 +35,9 @@ class HumanTaskModel(SpiffworkflowBaseDBModel): ForeignKey(ProcessInstanceModel.id), nullable=False # type: ignore ) lane_assignment_id: int | None = db.Column(ForeignKey(GroupModel.id)) - completed_by_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) + completed_by_user_id: int = db.Column(ForeignKey(UserModel.id), nullable=True) # type: ignore - actual_owner_id: int = db.Column(ForeignKey(UserModel.id)) + actual_owner_id: int = db.Column(ForeignKey(UserModel.id)) # type: ignore # actual_owner: RelationshipProperty[UserModel] = relationship(UserModel) form_file_name: str | None = db.Column(db.String(50)) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task_user.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task_user.py index 7d98880f..31823af8 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task_user.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/human_task_user.py @@ -29,4 +29,4 @@ class HumanTaskUserModel(SpiffworkflowBaseDBModel): human_task_id = db.Column( ForeignKey(HumanTaskModel.id), nullable=False, index=True # type: ignore ) - user_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) + user_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/principal.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/principal.py index c7efa860..ac8ee6a4 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/principal.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/principal.py @@ -27,7 +27,7 @@ class PrincipalModel(SpiffworkflowBaseDBModel): __table_args__ = (CheckConstraint("NOT(user_id IS NULL AND group_id IS NULL)"),) id = db.Column(db.Integer, primary_key=True) - user_id = db.Column(ForeignKey(UserModel.id), nullable=True, unique=True) + user_id = db.Column(ForeignKey(UserModel.id), nullable=True, unique=True) # type: ignore group_id = db.Column(ForeignKey(GroupModel.id), nullable=True, unique=True) user = relationship("UserModel", viewonly=True) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py index aa1440b4..31912c30 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance.py @@ -57,7 +57,7 @@ class ProcessInstanceModel(SpiffworkflowBaseDBModel): process_model_display_name: str = db.Column( db.String(255), nullable=False, index=True ) - process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) + process_initiator_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore process_initiator = relationship("UserModel") active_human_tasks = relationship( diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py index 1f22a383..b1288b3f 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/process_instance_report.py @@ -70,7 +70,7 @@ class ProcessInstanceReportModel(SpiffworkflowBaseDBModel): id: int = db.Column(db.Integer, primary_key=True) identifier: str = db.Column(db.String(50), nullable=False, index=True) report_metadata: dict = deferred(db.Column(db.JSON)) # type: ignore - created_by_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) + created_by_id = db.Column(ForeignKey(UserModel.id), nullable=False, index=True) # type: ignore created_by = relationship("UserModel") created_at_in_seconds = db.Column(db.Integer) updated_at_in_seconds = db.Column(db.Integer) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/secret_model.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/secret_model.py index 92fd470a..91a4f23b 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/secret_model.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/secret_model.py @@ -17,7 +17,7 @@ class SecretModel(SpiffworkflowBaseDBModel): id: int = db.Column(db.Integer, primary_key=True) key: str = db.Column(db.String(50), unique=True, nullable=False) value: str = db.Column(db.Text(), nullable=False) - user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) + user_id: int = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore updated_at_in_seconds: int = db.Column(db.Integer) created_at_in_seconds: int = db.Column(db.Integer) diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/user.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/user.py index 04996a73..c4838aaf 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/user.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/user.py @@ -26,9 +26,7 @@ class UserModel(SpiffworkflowBaseDBModel): __table_args__ = (db.UniqueConstraint("service", "service_id", name="service_key"),) id: int = db.Column(db.Integer, primary_key=True) - username: str = db.Column( - db.String(255), nullable=False, unique=True - ) + username: str = db.Column(db.String(255), nullable=False, unique=True) service = db.Column( db.String(255), nullable=False, unique=False diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/models/user_group_assignment.py b/spiffworkflow-backend/src/spiffworkflow_backend/models/user_group_assignment.py index fa5b620c..9c1567fb 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/models/user_group_assignment.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/models/user_group_assignment.py @@ -17,7 +17,7 @@ class UserGroupAssignmentModel(SpiffworkflowBaseDBModel): ) id = db.Column(db.Integer, primary_key=True) - user_id = db.Column(ForeignKey(UserModel.id), nullable=False) + user_id = db.Column(ForeignKey(UserModel.id), nullable=False) # type: ignore group_id = db.Column(ForeignKey(GroupModel.id), nullable=False) group = relationship("GroupModel", overlaps="groups,user_group_assignments,users") # type: ignore diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py index 2c7ceeea..a7d3bf86 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/tasks_controller.py @@ -434,7 +434,7 @@ def _get_tasks( ProcessInstanceModel.status.label("process_instance_status"), # type: ignore ProcessInstanceModel.updated_at_in_seconds, ProcessInstanceModel.created_at_in_seconds, - UserModel.username.label("process_initiator_username"), + UserModel.username.label("process_initiator_username"), # type: ignore GroupModel.identifier.label("assigned_user_group_identifier"), HumanTaskModel.task_name, HumanTaskModel.task_title, diff --git a/spiffworkflow-backend/src/spiffworkflow_backend/routes/users_controller.py b/spiffworkflow-backend/src/spiffworkflow_backend/routes/users_controller.py index 7fbc8317..5dce5b43 100644 --- a/spiffworkflow-backend/src/spiffworkflow_backend/routes/users_controller.py +++ b/spiffworkflow-backend/src/spiffworkflow_backend/routes/users_controller.py @@ -1,10 +1,10 @@ -"""users_controller.""" - +"""Users_controller.""" import flask -from spiffworkflow_backend.models.user import UserModel -from flask import make_response -from flask import jsonify from flask import g +from flask import jsonify +from flask import make_response + +from spiffworkflow_backend.models.user import UserModel def user_search(username_prefix: str) -> flask.wrappers.Response: diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_users_controller.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_users_controller.py index 6a2c51be..c1c62705 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_users_controller.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_users_controller.py @@ -1,9 +1,9 @@ -"""test_users_controller.""" - -from tests.spiffworkflow_backend.helpers.base_test import BaseTest -from spiffworkflow_backend.models.user import UserModel -from flask.testing import FlaskClient +"""Test_users_controller.""" from flask.app import Flask +from flask.testing import FlaskClient +from tests.spiffworkflow_backend.helpers.base_test import BaseTest + +from spiffworkflow_backend.models.user import UserModel class TestUsersController(BaseTest): @@ -22,13 +22,19 @@ class TestUsersController(BaseTest): self.find_or_create_user(username="abc") self.find_or_create_user(username="ac") - self._assert_search_has_count(client, with_super_admin_user, 'aa', 1) - self._assert_search_has_count(client, with_super_admin_user, 'ab', 2) - self._assert_search_has_count(client, with_super_admin_user, 'ac', 1) - self._assert_search_has_count(client, with_super_admin_user, 'ad', 0) - self._assert_search_has_count(client, with_super_admin_user, 'a', 4) + self._assert_search_has_count(client, with_super_admin_user, "aa", 1) + self._assert_search_has_count(client, with_super_admin_user, "ab", 2) + self._assert_search_has_count(client, with_super_admin_user, "ac", 1) + self._assert_search_has_count(client, with_super_admin_user, "ad", 0) + self._assert_search_has_count(client, with_super_admin_user, "a", 4) - def _assert_search_has_count(self, client: FlaskClient, with_super_admin_user: UserModel, username_prefix: str, expected_count: int) -> None: + def _assert_search_has_count( + self, + client: FlaskClient, + with_super_admin_user: UserModel, + username_prefix: str, + expected_count: int, + ) -> None: """_assert_search_has_count.""" response = client.get( f"/v1.0/users/search?username_prefix={username_prefix}", @@ -36,6 +42,6 @@ class TestUsersController(BaseTest): ) assert response.status_code == 200 assert response.json - assert response.json['users'] is not None - assert response.json['username_prefix'] == username_prefix - assert len(response.json['users']) == expected_count + assert response.json["users"] is not None + assert response.json["username_prefix"] == username_prefix + assert len(response.json["users"]) == expected_count