def step_impl(context, field_name, value): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: if ArgonautObservationDecider(res).should_validate(): found = utils.traverse(res, path) assert found, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_FIELD_NOT_PRESENT, resource=res, field=field_name, json=json.dumps(res, indent=2)) assert value in found, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_WRONG_FIXED, resource=res, values=found, value=value)
def step_impl(context, field_name, value_set_url_one, value_set_url_two): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) system_names = '{0} or {1}'.format(value_set_url_one, value_set_url_two) for res in resources: found = utils.traverse(res, path) if isinstance(found, str): found = [found] elif isinstance(found, dict): assert 'coding' in found, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_CODING_MISSING, resource=res, field_name=field_name, json=json.dumps(found, indent=2)) found = [ coding.get('code') for coding in found.get('coding') if in_value_set(coding, value_set_url_one) or in_value_set(coding, value_set_url_two) ] assert found, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_MISSING_SYSTEM_CODING, resource=res, field_name=field_name, system=system_names) for code in found: try: valid = systems.validate_code(code, value_set_url_one) or \ systems.validate_code(code, value_set_url_two) except systems.SystemNotRecognized: valid = False assert valid, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_INVALID_BINDING, resource=res, code=code, system=system_names, json=json.dumps(res, indent=2))
def step_impl(context, system_url, field_name): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) bad_resource_results = [] for res in resources: if ArgonautObservationDecider(res).should_validate(): found = utils.traverse(res, path) if found: vital_validation_status = vital_unit_validation(field_name, res, system_url) if vital_validation_status: bad_resource_results.append(vital_validation_status) assert len(bad_resource_results) == 0, utils.bad_response_assert_with_resource( response=context.response, message=ERROR_UCUM_CODES, resource=bad_resource_results, field_name=field_name)
def step_impl(context, field_name, value_set_url_one, value_set_url_two): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) system_names = '{0} or {1}'.format(value_set_url_one, value_set_url_two) for res in resources: found = utils.traverse(res, path) if isinstance(found, str): found = [found] elif isinstance(found, dict): assert 'coding' in found, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_CODING_MISSING, resource=res, field_name=field_name, json=json.dumps(found, indent=2)) found = [coding.get('code') for coding in found.get('coding') if in_value_set(coding, value_set_url_one) or in_value_set(coding, value_set_url_two)] assert found, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_MISSING_SYSTEM_CODING, resource=res, field_name=field_name, system=system_names) for code in found: try: valid = systems.validate_code(code, value_set_url_one) or \ systems.validate_code(code, value_set_url_two) except systems.SystemNotRecognized: valid = False assert valid, utils.bad_response_assert_with_resource(response=context.response, message=ERROR_INVALID_BINDING, resource=res, code=code, system=system_names, json=json.dumps(res, indent=2))
def step_impl(context, name, field_name): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: found = utils.traverse(res, path) assert found is not None, utils.bad_response_assert_with_resource(response=context.response, message=ERROR_REQUIRED, name=name, resource=res)
def step_impl(context, field_name, sub_field): if not StepDecider(context).should_run_test(): return path = field_name.split('.') filter_type = path.pop(0) sub_path = sub_field.split('.') sub_type = sub_path.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: found = utils.traverse(res, path) for item in found: match = utils.traverse(item, sub_path) assert match is not None, \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_REQUIRED, resource=res, name=sub_type)
def step_impl(context, name, field_one_name, field_two_name): if not StepDecider(context).should_run_test(): return path_one = field_one_name.split('.') path_two = field_two_name.split('.') filter_type = path_one.pop(0) assert filter_type == path_two.pop(0) resources = get_resources(context.response.json(), filter_type) for res in resources: found_one = utils.traverse(res, path_one) found_two = utils.traverse(res, path_two) assert (found_one is not None) or (found_two is not None), \ utils.bad_response_assert_with_resource(response=context.response, message=ERROR_REQUIRED, resource=res, name=name )