Exemplo n.º 1
0
def test_validation_backends():
    from prance.util import validation_backends

    backends = validation_backends()

    assert 'flex' in backends

    if len(backends) > 1:
        assert 'swagger-spec-validator' in backends

        # Only exists for Python 3
        import sys
        if sys.version_info[0] == 3:
            assert 'openapi-spec-validator' in backends
Exemplo n.º 2
0
def test_convert_parser_lazy_swagger_backend():
    from prance import BaseParser, ResolvingParser, ValidationError
    parser = BaseParser('tests/petstore.yaml')

    # Conversion should fail with the default backend.
    with pytest.raises(ValidationError):
        converted = convert.convert_spec(parser)

    # However, with the lazy flag it should work.
    converted = convert.convert_spec(parser, lazy=True)
    assert isinstance(converted, BaseParser)

    # Passing a ResolvingParser class should also work.
    converted = convert.convert_spec(parser, ResolvingParser, lazy=True)
    assert isinstance(converted, ResolvingParser)


from prance.util import validation_backends
if 'openapi-spec-validator' in validation_backends():

    def test_convert_parser_validated():
        from prance import BaseParser
        parser = BaseParser('tests/petstore.yaml',
                            backend='openapi-spec-validator')

        # Conversion should work: it's the right backend, and it validates.
        converted = convert.convert_spec(parser)
        assert isinstance(converted, BaseParser)
        assert converted.version_parsed[0] == 3
Exemplo n.º 3
0
def %s():
  import os
  cur = os.getcwd()

  os.chdir('%s')

  from prance import %s
  try:
    parser = %s('%s', backend = '%s')
  finally:
    os.chdir(cur)
""" % (testcase_name, dirname, parser, parser, absurl, backend)
            print(code)
            exec(code, globals())


for parser in ('BaseParser', 'ResolvingParser'):
    from prance.util import validation_backends
    for backend in validation_backends():
        for version in os.listdir(base):
            version_dir = os.path.join(base, version)
            for file_format in os.listdir(version_dir):
                format_dir = os.path.join(version_dir, file_format)

                if not os.path.isdir(format_dir):  # Assume YAML
                    iter_entries(parser, backend, version, 'yaml', version_dir)
                else:
                    for entry in os.listdir(format_dir):
                        iter_entries(parser, backend, version, file_format,
                                     format_dir)
Exemplo n.º 4
0
def test_flex_issue_5_integer_keys():
    # Must succeed with default (flex) parser; note the parser does not stringify the response code
    parser = BaseParser('tests/issue_5.yaml', backend='flex')
    assert 200 in parser.specification['paths']['/test']['post']['responses']


def test_flex_validate_success():
    parser = BaseParser('tests/petstore.yaml', backend='flex')


def test_flex_validate_failure():
    with pytest.raises(ValidationError):
        parser = BaseParser('tests/missing_reference.yaml', backend='flex')


if 'swagger-spec-validator' in validation_backends():

    def test_swagger_spec_validator_issue_5_integer_keys():
        # Must fail in implicit strict mode.
        with pytest.raises(ValidationError):
            BaseParser('tests/issue_5.yaml', backend='swagger-spec-validator')

        # Must fail in explicit strict mode.
        with pytest.raises(ValidationError):
            BaseParser('tests/issue_5.yaml',
                       backend='swagger-spec-validator',
                       strict=True)

        # Must succeed in non-strict/lenient mode
        parser = BaseParser('tests/issue_5.yaml',
                            backend='swagger-spec-validator',