Example #1
0
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)
Example #2
0
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)
Example #3
0
def step_impl(context, field_name, value_set_url):
    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)
            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)
                ]

            assert found, \
                utils.bad_response_assert_with_resource(response=context.response,
                                                        message=ERROR_MISSING_SYSTEM_CODING,
                                                        resource=res,
                                                        field_name=field_name,
                                                        system=value_set_url)

            for code in found:
                try:
                    valid = systems.validate_code(code, value_set_url)
                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=value_set_url,
                    json=json.dumps(res, indent=2))
Example #4
0
def step_impl(context, field_string, resource):

    if not StepDecider(context).should_run_test():
        return

    fields_to_find = field_string.split(",")

    resources = get_resources(context.response.json(), resource)

    valid_resource_ids = set([
        res.get("id") for res in resources
        if not ArgonautObservationDecider(res).should_validate() or
        utils.has_one_of(res, fields_to_find)])

    all_resource_ids = set([res.get("id") for res in resources])

    invalid_resource_ids = all_resource_ids - valid_resource_ids

    assert len(invalid_resource_ids) == 0, \
        utils.bad_response_assert(context.response,
                                  ERROR_MISSING_FIELD,
                                  resource_ids=', '.join(invalid_resource_ids),
                                  field_list=field_string)
Example #5
0
def test_argonaut_validation():
    resources = VitalsResource().get_resources()

    assert ArgonautObservationDecider(resources[0]).should_validate()
    assert not ArgonautObservationDecider(resources[1]).should_validate()