How to use the prance.util.url.fetch_url function in prance

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_util_url.py View on Github external
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'
github jfinkhaeuser / prance / tests / test_util_url.py View on Github external
def test_fetch_url_python():
  exturl = 'python://tests/specs/petstore.yaml'
  content = url.fetch_url(url.absurl(exturl))
  assert content['swagger'] == '2.0'
github jfinkhaeuser / prance / tests / test_util_url.py View on Github external
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'])
github jfinkhaeuser / prance / tests / test_util_url.py View on Github external
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'
github jfinkhaeuser / prance / tests / test_util_url.py View on Github external
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'])
github jfinkhaeuser / prance / prance / __init__.py View on Github external
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!'