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_fetch_url_file():
from prance.util import fs
content = url.fetch_url(url.absurl(fs.abspath('tests/specs/with_externals.yaml')))
assert content['swagger'] == '2.0'
def test_fetch_url_python():
exturl = 'python://tests/specs/petstore.yaml'
content = url.fetch_url(url.absurl(exturl))
assert content['swagger'] == '2.0'
def test_fetch_url_cached():
from prance.util import fs
cache = {}
content1 = url.fetch_url(url.absurl(fs.abspath('tests/specs/with_externals.yaml')), cache)
assert content1['swagger'] == '2.0'
content2 = url.fetch_url(url.absurl(fs.abspath('tests/specs/with_externals.yaml')), cache)
assert content2['swagger'] == '2.0'
# Dicts are mutable, therefore we can't compare IDs. But individual
# string fields should not be copied, because we shallow copy.
assert id(content1['swagger']) == id(content2['swagger'])
def test_fetch_url_http():
exturl = 'http://finkhaeuser.de/projects/prance/petstore.yaml'\
'#/definitions/Pet'
content = url.fetch_url(url.absurl(exturl))
assert content['swagger'] == '2.0'
def test_fetch_url_cached():
from prance.util import fs
cache = {}
content1 = url.fetch_url(url.absurl(fs.abspath('tests/specs/with_externals.yaml')), cache)
assert content1['swagger'] == '2.0'
content2 = url.fetch_url(url.absurl(fs.abspath('tests/specs/with_externals.yaml')), cache)
assert content2['swagger'] == '2.0'
# Dicts are mutable, therefore we can't compare IDs. But individual
# string fields should not be copied, because we shallow copy.
assert id(content1['swagger']) == id(content2['swagger'])
def parse(self): # noqa: F811
"""
When the BaseParser was lazily created, load and parse now.
You can use this function to re-use an existing parser for parsing
multiple files by setting its url property and then invoking this
function.
"""
# If we have a file name, we need to read that in.
if self.url and self.url != _PLACEHOLDER_URL:
from .util.url import fetch_url
encoding = self.options.get('encoding', None)
self.specification = fetch_url(self.url, encoding = encoding)
# If we have a spec string, try to parse it.
if self._spec_string:
from .util.formats import parse_spec
self.specification = parse_spec(self._spec_string, self.url)
# Perform some sanitization in lenient mode.
if not self.options.get('strict', True):
from .util import stringify_keys
self.specification = stringify_keys(self.specification)
# If we have a parsed spec, convert it to JSON. Then we can validate
# the JSON. At this point, we *require* a parsed specification to exist,
# so we might as well assert.
assert self.specification, 'No specification parsed, cannot validate!'