From ed3efd6d07928ceec1d555e00e3914bcd229b733 Mon Sep 17 00:00:00 2001 From: mike cullerton Date: Sat, 19 Nov 2022 14:47:50 -0500 Subject: [PATCH] test for move model --- .../integration/test_process_api.py | 69 ++++++++++++++++--- 1 file changed, 60 insertions(+), 9 deletions(-) diff --git a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py index 3279b9df..490435a8 100644 --- a/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py +++ b/spiffworkflow-backend/tests/spiffworkflow_backend/integration/test_process_api.py @@ -2370,15 +2370,8 @@ class TestProcessApi(BaseTest): print("test_script_unit_test_run") - def test_move_model(self): - ... - - def test_move_group( - self, - app: Flask, - client: FlaskClient, - with_db_and_bpmn_file_cleanup: None, - with_super_admin_user: UserModel, + def setup_initial_groups_for_move_tests( + self, client: FlaskClient, with_super_admin_user: UserModel ) -> None: groups = [ 'group_a', 'group_b', 'group_b/group_bb' @@ -2397,6 +2390,64 @@ class TestProcessApi(BaseTest): assert persisted is not None assert persisted.id == group + def test_move_model( + self, + app: Flask, + client: FlaskClient, + with_db_and_bpmn_file_cleanup: None, + with_super_admin_user: UserModel, + ): + """test_move_model.""" + self.setup_initial_groups_for_move_tests(client, with_super_admin_user) + + process_model_id = 'test_model' + original_location = "group_a" + original_process_model_path = f"{original_location}/{process_model_id}" + + # add model to `group_a` + self.create_process_model_with_api( + client, + original_process_model_path, + user=with_super_admin_user, + process_model_display_name=process_model_id, + process_model_description=process_model_id + ) + persisted = ProcessModelService().get_process_model(original_process_model_path) + assert persisted is not None + assert persisted.id == original_process_model_path + + # move model to `group_b/group_bb` + new_location = 'group_b/group_bb' + new_process_model_path = f"{new_location}/{process_model_id}" + modified_original_process_model_id = original_process_model_path.replace("/", ":") + + response = client.put( + f"/v1.0/process-models/{modified_original_process_model_id}/move?new_location={new_location}", + headers=self.logged_in_headers(with_super_admin_user), + ) + assert response.status_code == 201 + assert response.json['id'] == new_process_model_path + + # make sure the original model does not exist + with pytest.raises(ProcessEntityNotFoundError) as e: + ProcessModelService().get_process_model(original_process_model_path) + assert e.value.args[0] == 'process_model_not_found' + + # make sure the new model does exist + new_process_model = ProcessModelService().get_process_model(new_process_model_path) + assert new_process_model is not None + assert new_process_model.id == new_process_model_path + + def test_move_group( + self, + app: Flask, + client: FlaskClient, + with_db_and_bpmn_file_cleanup: None, + with_super_admin_user: UserModel, + ) -> None: + """test_move_group.""" + self.setup_initial_groups_for_move_tests(client, with_super_admin_user) + # add sub group to `group_a` sub_group_id = 'sub_group' original_location = 'group_a'