Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_convert_url():
from prance.util import url
converted, content_type = convert.convert_url(url.absurl('python://tests/specs/petstore.yaml'))
# Check correct content type
assert 'yaml' in content_type
# Parsing can't fail.
from prance.util import formats
parsed = formats.parse_spec(converted, content_type = content_type)
# Assert the correct target version
assert 'openapi' in parsed
assert parsed['openapi'].startswith('3.')
def test_parse_unknown_ctype():
with pytest.raises(formats.ParseError):
formats.parse_spec('{-', None, content_type = 'text/xml')
def test_parse_yaml_ctype():
yaml = """---
foo: bar
"""
parsed = formats.parse_spec(yaml, None, content_type = 'text/yaml')
assert parsed['foo'] == 'bar', 'Did not parse with explicit YAML'
def test_parse_unknown():
with pytest.raises(formats.ParseError):
formats.parse_spec('{-')
def test_parse_json():
json = '{ "foo": "bar" }'
parsed = formats.parse_spec(json, 'foo.js')
assert parsed['foo'] == 'bar', 'Did not parse with explicit JSON'
def test_parse_unknown_ext():
with pytest.raises(formats.ParseError):
formats.parse_spec('{-', 'asdf.xml')