-
Notifications
You must be signed in to change notification settings - Fork 338
/
Copy pathtest_schemas.py
52 lines (41 loc) · 1.44 KB
/
test_schemas.py
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
42
43
44
45
46
47
48
49
50
51
52
import pytest
from jsonschema import ValidationError
from flask_restx import errors, schemas
class SchemasTest:
def test_lazyness(self):
schema = schemas.LazySchema("oas-2.0.json")
assert schema._schema is None
"" in schema # Trigger load
assert schema._schema is not None
assert isinstance(schema._schema, dict)
def test_oas2_schema_is_present(self):
assert hasattr(schemas, "OAS_20")
assert isinstance(schemas.OAS_20, schemas.LazySchema)
class ValidationTest:
def test_oas_20_valid(self):
assert schemas.validate(
{
"swagger": "2.0",
"info": {
"title": "An empty minimal specification",
"version": "1.0",
},
"paths": {},
}
)
def test_oas_20_invalid(self):
with pytest.raises(schemas.SchemaValidationError) as excinfo:
schemas.validate(
{
"swagger": "2.0",
"should": "not be here",
}
)
for error in excinfo.value.errors:
assert isinstance(error, ValidationError)
def test_unknown_schema(self):
with pytest.raises(errors.SpecsError):
schemas.validate({"valid": "no"})
def test_unknown_version(self):
with pytest.raises(errors.SpecsError):
schemas.validate({"swagger": "42.0"})