def test_sidecar_process_empty_file(self):
     from hedweb.sidecar import process
     from hed.errors.exceptions import HedFileError
     with self.app.app_context():
         arguments = {'json_path': ''}
         try:
             process(arguments)
         except HedFileError:
             pass
         except Exception:
             self.fail('process threw the wrong exception when sidecar path was empty')
         else:
             self.fail('process should have thrown a HedFileError exception when json_path was empty')
Beispiel #2
0
def sidecar_results():
    """Process the JSON sidecar after form submission and return an attachment containing the output.

    Returns
    -------
        download file
        A text file with the validation errors or a converted sidecar.
    """

    try:
        input_arguments = sidecar.get_input_from_form(request)
        a = sidecar.process(input_arguments)
        return package_results(a)
    except Exception as ex:
        return handle_http_error(ex)
    def test_sidecar_process_valid_to_short_defs_expanded(self):
        from hedweb.sidecar import process
        json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events.json')
        json_sidecar = models.Sidecar(file=json_path, name='bids_events')
        schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/HED8.0.0.xml')
        hed_schema = hedschema.load_schema(schema_path)
        arguments = {base_constants.SCHEMA: hed_schema, base_constants.JSON_SIDECAR: json_sidecar,
                     base_constants.JSON_DISPLAY_NAME: 'bids_events',
                     base_constants.EXPAND_DEFS: True,
                     base_constants.COMMAND: base_constants.COMMAND_TO_SHORT}

        with self.app.app_context():
            results = process(arguments)
            self.assertTrue(isinstance(results, dict),
                            'process to short should return a dict when no errors and defs expanded')
            self.assertEqual('success', results['msg_category'],
                             'process to short should return success if no errors and defs_expanded')
    def test_sidecar_process_invalid(self):
        from hedweb.sidecar import process
        json_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/bids_events_bad.json')
        json_sidecar = models.Sidecar(file=json_path, name='bids_events_bad')
        schema_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data/HED8.0.0.xml')
        hed_schema = hedschema.load_schema(schema_path)

        arguments = {base_constants.SCHEMA: hed_schema, base_constants.JSON_SIDECAR: json_sidecar,
                     base_constants.JSON_DISPLAY_NAME: 'bids_events_bad',
                     base_constants.COMMAND: base_constants.COMMAND_TO_SHORT}
        with self.app.app_context():
            results = process(arguments)
            self.assertTrue(isinstance(results, dict),
                            'process to short should return a dictionary when errors')
            self.assertEqual('warning', results['msg_category'],
                             'process to short should give warning when JSON with errors')
            self.assertTrue(results['data'],
                            'process to short should not convert using HED 8.0.0.xml')
Beispiel #5
0
def process(arguments):
    """
    Calls the desired service processing function and returns results

    Parameters
    ----------
    arguments: dict
        a dictionary of arguments for the processing

    Returns
    -------
    dist
        A dictionary of results in standard response format to be jsonified.
    """

    command = arguments.get(base_constants.COMMAND, '')
    target = arguments.get(base_constants.COMMAND_TARGET, '')
    response = {
        base_constants.SERVICE: arguments.get(base_constants.SERVICE, ''),
        base_constants.COMMAND: command,
        base_constants.COMMAND_TARGET: target,
        'results': '',
        'error_type': '',
        'error_msg': ''
    }

    if not arguments.get(base_constants.SERVICE, ''):
        response["error_type"] = 'HEDServiceMissing'
        response["error_msg"] = "Must specify a valid service"
    elif command == 'get_services':
        response["results"] = services_list()
    elif target == "events":
        response["results"] = events.process(arguments)
    elif target == "sidecar":
        response["results"] = sidecar.process(arguments)
    elif target == "spreadsheet":
        results = spreadsheet.process(arguments)
        response["results"] = package_spreadsheet(results)
    elif target == "strings":
        response["results"] = strings.process(arguments)
    else:
        response["error_type"] = 'HEDServiceNotSupported'
        response["error_msg"] = f"{command} for {target} not supported"
    return response