How to use prance - 10 common examples

To help you get started, we’ve selected a few prance examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jfinkhaeuser / prance / tests / test_backends.py View on Github external
def test_flex_validate_failure():
  with pytest.raises(ValidationError):
    parser = BaseParser('tests/specs/missing_reference.yaml', backend = 'flex')
github jfinkhaeuser / prance / tests / test_backends.py View on Github external
def test_openapi_spec_validator_validate_failure():
  with pytest.raises(ValidationError):
    parser = BaseParser('tests/specs/missing_reference.yaml', backend = 'openapi-spec-validator')
github jfinkhaeuser / prance / tests / test_convert.py View on Github external
def test_convert_spec():
  from prance import BaseParser, ResolvingParser, ValidationError
  parser = BaseParser('tests/specs/petstore.yaml')

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

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

  # Passing a ResolvingParser class should also work.
  converted = convert.convert_spec(parser.specification, ResolvingParser, lazy = True)
  assert isinstance(converted, ResolvingParser)
github jfinkhaeuser / prance / tests / test_backends.py View on Github external
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/specs/issue_5.yaml', backend = 'flex')
  assert 200 in parser.specification['paths']['/test']['post']['responses']
github jfinkhaeuser / prance / tests / test_backends.py View on Github external
def test_swagger_spec_validator_validate_failure():
  with pytest.raises(ValidationError):
    parser = BaseParser('tests/specs/missing_reference.yaml', backend = 'swagger-spec-validator')
github jfinkhaeuser / prance / tests / test_backends.py View on Github external
def test_openapi_spec_validator_issue_20_spec_version_handling():
  # The spec is OpenAPI 3, but broken. Need to set 'strict' to False to stringify keys
  with pytest.raises(ValidationError):
    parser = BaseParser('tests/specs/issue_20.yaml', backend = 'openapi-spec-validator', strict = False)

  # Lazy parsing should let us validate what's happening
  parser = BaseParser('tests/specs/issue_20.yaml', backend = 'openapi-spec-validator', strict = False, lazy = True)
  assert not parser.valid
  assert parser.version_parsed == ()

  with pytest.raises(ValidationError):
    parser.parse()

  # After parsing, the specs are not valid, but the correct version is
  # detected.
  assert not parser.valid
  assert parser.version_parsed == (3, 0, 0)
github jfinkhaeuser / prance / tests / test_backends.py View on Github external
def test_swagger_spec_validator_issue_5_integer_keys():
  # Must fail in implicit strict mode.
  with pytest.raises(ValidationError):
    BaseParser('tests/specs/issue_5.yaml', backend = 'swagger-spec-validator')

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

  # Must succeed in non-strict/lenient mode
  parser = BaseParser('tests/specs/issue_5.yaml', backend = 'swagger-spec-validator', strict = False)
  assert '200' in parser.specification['paths']['/test']['post']['responses']
github jfinkhaeuser / prance / tests / test_convert.py View on Github external
def test_convert_parser_lazy_swagger_backend():
  from prance import BaseParser, ResolvingParser, ValidationError
  parser = BaseParser('tests/specs/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)
github jfinkhaeuser / prance / tests / test_util_path.py View on Github external
value = 42

  # No path can be resolved in a value type
  result = None
  with pytest.raises(TypeError):
    result = path_get(value, ('foo', 'bar'), 123)
  assert result is None

  # However, we can resolve zero length paths
  result = path_get(value, (), 123)
  assert 42 == result
  result = path_get(None, (), 123)
  assert 123 == result

  # Also we can resolve None-type paths
  result = path_get(value, None, 321)
  assert 42 == result
  result = path_get(None, None, 321)
  assert 321 == result
github jfinkhaeuser / prance / tests / test_util_path.py View on Github external
def test_get_mapping_default():
  value = { 'foo': 1, 'bar': 2, 3: 3 }

  # String paths should work in a Mapping
  result = path_get(value, ('foo',), 123)
  assert 1 == result

  # So should numeric keys
  result = path_get(value, (3,), 123)
  assert 3 == result

  # Zero length paths should return the value or default value
  result = path_get(value, (), 123)
  assert { 'foo': 1, 'bar': 2, 3: 3 } == result
  result = path_get(None, (), 123)
  assert 123 == result

  # And None paths as well
  result = path_get(value, None, 321)
  assert { 'foo': 1, 'bar': 2, 3: 3 } == result
  result = path_get(None, None, 321)
  assert 321 == result