File: deref_test.py

package info (click to toggle)
swagger-spec-validator 3.0.4-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 696 kB
  • sloc: python: 2,321; makefile: 28; sh: 2
file content (34 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from unittest.mock import Mock

import pytest
from jsonschema.exceptions import RefResolutionError
from jsonschema.validators import RefResolver

from swagger_spec_validator.validator20 import deref


def test_none():
    assert deref(None, Mock(spec=RefResolver)) is None


def test_not_dict():
    assert deref(1, Mock(spec=RefResolver)) == 1


def test_not_ref():
    input = {"type": "object"}
    assert deref(input, Mock(spec=RefResolver)) == input


def test_ref():
    ref_dict = {"$ref": "#/definitions/Foo"}
    definitions = {"definitions": {"Foo": "bar"}}
    assert deref(ref_dict, RefResolver("", definitions)) == "bar"


def test_ref_not_found():
    ref_dict = {"$ref": "#/definitions/Foo"}
    definitions = {}
    with pytest.raises(RefResolutionError) as excinfo:
        deref(ref_dict, RefResolver("", definitions))
    assert "Unresolvable JSON pointer" in str(excinfo.value)