diff --git a/hedweb/process_service.py b/hedweb/process_service.py index 7ad507c3..c7812205 100644 --- a/hedweb/process_service.py +++ b/hedweb/process_service.py @@ -136,8 +136,11 @@ def set_input_objects(arguments, params): has_column_names=True, column_prefix_dictionary=None, name='spreadsheets.tsv') if bc.STRING_LIST in params and params[bc.STRING_LIST]: + working_list = params[bc.STRING_LIST] + if isinstance(working_list, str): + working_list = [working_list] s_list = [] - for s in params[bc.STRING_LIST]: + for s in working_list: s_list.append(HedString(s, hed_schema=schema)) arguments[bc.STRING_LIST] = s_list diff --git a/hedweb/string_operations.py b/hedweb/string_operations.py index d778d2a7..761de168 100644 --- a/hedweb/string_operations.py +++ b/hedweb/string_operations.py @@ -1,12 +1,10 @@ -import json from hed.errors import ErrorHandler, get_printable_issue_string, HedFileError from hed import schema as hedschema from hed import get_query_handlers, search_hed_objs from hed.validator import HedValidator - from hedweb.constants import base_constants as bc from hedweb.base_operations import BaseOperations -from hedweb.web_util import generate_filename + class StringOperations(BaseOperations): @@ -130,13 +128,13 @@ def validate(self): validation_issues = [] error_handler = ErrorHandler(check_for_warnings=self.check_for_warnings) validator = HedValidator(self.schema, self.definitions) - for pos, h_string in enumerate(self.string_list, start=1): + for pos, h_string in enumerate(self.string_list): issues = validator.validate(h_string, True, error_handler=error_handler) if issues: validation_issues.append(get_printable_issue_string(issues, f"Errors for HED string {pos}:")) if validation_issues: return {bc.COMMAND: bc.COMMAND_VALIDATE, - bc.COMMAND_TARGET: 'strings', 'data': validation_issues, + bc.COMMAND_TARGET: 'strings', 'data': '\n'.join(validation_issues), bc.SCHEMA_VERSION: self.schema.get_formatted_version(), 'msg_category': 'warning', 'msg': 'Strings had validation issues'} diff --git a/tests/test_routes/test_routes_services_strings.py b/tests/test_routes/test_routes_services_strings.py index 8e19c87d..88ef7bcf 100644 --- a/tests/test_routes/test_routes_services_strings.py +++ b/tests/test_routes/test_routes_services_strings.py @@ -29,6 +29,7 @@ def test_submit_service_strings_validate_route_file_invalid(self): response = self.app.test.post('/services_submit', content_type='application/json', data=json.dumps(json_data)) + x = response.data json_data2 = json.loads(response.data) results = json_data2['results'] self.assertTrue(isinstance(results, dict), "should return a dictionary when validation errors") @@ -39,7 +40,7 @@ def test_submit_service_strings_validate_route_file_invalid_format(self): with self.app.app_context(): json_data = {bc.CHECK_FOR_WARNINGS: 'on', bc.SCHEMA_VERSION: '8.2.0', - bc.STRING_LIST: "Blech", + bc.STRING_LIST: 'Blech', bc.SERVICE: 'strings_validate'} response = self.app.test.post('/services_submit', content_type='application/json', @@ -49,4 +50,4 @@ def test_submit_service_strings_validate_route_file_invalid_format(self): self.assertTrue(isinstance(results, dict), "should return a dictionary when validation errors") self.assertEqual('warning', results['msg_category'], "should give warning with issues") self.assertTrue(results["data"], 'process return data for issues') - self.assertEqual(len(results["data"]), 5, "Server is allowing a string as a string list input") + self.assertEqual(len(results["data"]), 84, "Server is allowing a string as a string list input")