File: get_validator_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 (41 lines) | stat: -rw-r--r-- 1,369 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
35
36
37
38
39
40
41
import pytest

from swagger_spec_validator import validator12
from swagger_spec_validator import validator20
from swagger_spec_validator.common import SwaggerValidationError
from swagger_spec_validator.util import get_validator


def test_version_missing():
    with pytest.raises(SwaggerValidationError) as excinfo:
        get_validator({}, "http://foo.com")
    assert "missing" in str(excinfo.value)


def test_1_dot_x_version_not_supported():
    with pytest.raises(SwaggerValidationError) as excinfo:
        get_validator({"swaggerVersion": "0.9"}, "http://foo.com")
    assert "not supported" in str(excinfo.value)


def test_2_dot_x_version_not_supported():
    with pytest.raises(SwaggerValidationError) as excinfo:
        get_validator({"swagger": "1.2"}, "http://foo.com")
    assert "not supported" in str(excinfo.value)


def test_both_swagger_1_dot_x_and_2_dot_x_version_keys_found():
    with pytest.raises(SwaggerValidationError) as excinfo:
        spec = {"swagger": "2.0", "swaggerVersion": "1.2"}
        get_validator(spec, "http://foo.com")
    assert "not both" in str(excinfo.value)


def test_success_12():
    spec = {"swaggerVersion": "1.2"}
    assert validator12 == get_validator(spec, "http://foo.com") == validator12


def test_success_20():
    spec = {"swagger": "2.0"}
    assert validator20 == get_validator(spec, "http://foo.com")