def test_clone_workflow_failure(fx_get_sub_parser, fx_cmd_line_args_clone_prefix): """ Test when calling 'clone' command and providing a non existant source workflow that an exception is raised as expected and has the correct message """ old_name = "non_existant_workflow" new_name = "new_mocked_workflow" # Get sub_parser object, its dest is cmd cmd_clone = CmdClone(fx_get_sub_parser) expected_error = "Workflow: '{}' not found in this export.".format( old_name) with pytest.raises(SDKException) as excinfo: export_data = cmd_clone._clone_workflow( Namespace(workflow=[old_name, new_name], changetype=""), TEST_EXPORT) original_obj = CmdClone.validate_provided_object_names(obj_type="workflows", obj_identifier=ResilientObjMap.WORKFLOWS, obj_type_name="Workflow", new_object_api_name=new_name, original_object_api_name=old_name, export=TEST_EXPORT) # Gather the message from the execution info, throwing away the other args exception_message, = excinfo.value.args assert expected_error in exception_message
def test_clone_workflow(fx_get_sub_parser): """test_clone_workflow test which verifies a known named workflow can be cloned with a new name _clone_workflow performs these 3 high level steps : 1: Validate only 2 names are provided OR that prefix is provided 2: Validate the source object exists and the target object name will not cause a duplicate 3: Perform the clone :param fx_get_sub_parser: a fixture mocking the functionality of a argparse subparser :type fx_get_sub_parser: fixture """ old_name = "mock_workflow_two" new_name = "new_mocked_workflow" # Get sub_parser object, its dest is cmd cmd_clone = CmdClone(fx_get_sub_parser) export_data = cmd_clone._clone_workflow( Namespace(workflow=[old_name, new_name], changetype=""), TEST_EXPORT) original_obj = CmdClone.validate_provided_object_names(obj_type="workflows", obj_identifier=ResilientObjMap.WORKFLOWS, obj_type_name="Workflow", new_object_api_name=new_name, original_object_api_name=old_name, export=TEST_EXPORT) assert export_data[0]['name'] != old_name, "Expected the returned export data to not have a reference to the old function" assert export_data[0][ResilientObjMap.WORKFLOWS] == new_name, "Expected the returned export to contain the new function name" # Ensure the Object specific primary key is not duplicated assert export_data[0][ResilientObjMap.WORKFLOWS] != original_obj[ ResilientObjMap.WORKFLOWS], "Expected that the export_key was updated"
def test_clone_change_type(fx_get_sub_parser, fx_cmd_line_args_clone_typechange): """ Test to verify when specifying the --changetype arg when cloning a workflow that the newly cloned workflow has its type changed as expected """ cmd_clone = CmdClone(fx_get_sub_parser) args = cmd_clone.parser.parse_known_args()[0] assert args.changetype == "task" export_data = cmd_clone._clone_workflow(args, TEST_EXPORT) old_name, new_name = args.workflow original_obj = CmdClone.validate_provided_object_names(obj_type="workflows", obj_identifier=ResilientObjMap.WORKFLOWS, obj_type_name="Workflow", new_object_api_name=new_name, original_object_api_name=old_name, export=TEST_EXPORT) assert export_data[0]['name'] != old_name, "Expected the returned export data to not have a reference to the old function" assert export_data[0][ResilientObjMap.WORKFLOWS] == new_name, "Expected the returned export to contain the new function name" # Ensure the Object specific primary key is not duplicated assert export_data[0][ResilientObjMap.WORKFLOWS] != original_obj[ ResilientObjMap.WORKFLOWS], "Expected that the export_key was updated" assert export_data[0]['object_type'] == 'task', "Expected the new workflows object_type to be set to task" assert export_data[0]['object_type'] != original_obj['object_type'], "Expected the cloned workflow to have a different object type to before"