File: validate_json_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 (22 lines) | stat: -rw-r--r-- 734 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
import json

import pytest

from swagger_spec_validator.common import SwaggerValidationError
from swagger_spec_validator.validator12 import validate_json


def test_success():
    with open("./tests/data/v1.2/foo/swagger_api.json") as f:
        resource_listing = json.load(f)
    validate_json(resource_listing, "schemas/v1.2/resourceListing.json")

    with open("./tests/data/v1.2/foo/foo.json") as f:
        api_declaration = json.load(f)
    validate_json(api_declaration, "schemas/v1.2/apiDeclaration.json")


def test_failure():
    with pytest.raises(SwaggerValidationError) as excinfo:
        validate_json({}, "schemas/v1.2/apiDeclaration.json")
    assert "'swaggerVersion' is a required property" in str(excinfo.value)