Skip to content

Commit

Permalink
Merge pull request #186 from VisLab/develop
Browse files Browse the repository at this point in the history
Updated the issue format for tag validation
  • Loading branch information
VisLab authored Jun 7, 2024
2 parents 702957c + b1c71b8 commit 30586d6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
5 changes: 4 additions & 1 deletion hedweb/process_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 3 additions & 5 deletions hedweb/string_operations.py
Original file line number Diff line number Diff line change
@@ -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):

Expand Down Expand Up @@ -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'}
Expand Down
5 changes: 3 additions & 2 deletions tests/test_routes/test_routes_services_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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',
Expand All @@ -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")

0 comments on commit 30586d6

Please sign in to comment.