Skip to content

Commit

Permalink
Test: Add serialize_schema tests
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjr0719 committed Jun 20, 2019
1 parent 74fd710 commit 43b4c9d
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions tests/test_fields.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from datetime import date, datetime

import pytest
from sanic.response import text

Expand Down Expand Up @@ -220,3 +222,43 @@ def test(request):
"type": "string",
"format": "date-time",
}


class TestSchema:
pass


@pytest.mark.parametrize(
"schema, expected_schema",
[
(doc.Field, {}),
(doc.Field(), {}),
(int, {"type": "integer", "format": "int64"}),
(doc.Integer, {"type": "integer", "format": "int64"}),
(doc.Integer(), {"type": "integer", "format": "int64"}),
(float, {"type": "number", "format": "double"}),
(doc.Float, {"type": "number", "format": "double"}),
(doc.Float(), {"type": "number", "format": "double"}),
(str, {"type": "string"}),
(doc.String, {"type": "string"}),
(doc.String(), {"type": "string"}),
(bool, {"type": "boolean"}),
(doc.Boolean, {"type": "boolean"}),
(doc.Boolean(), {"type": "boolean"}),
(date, {"type": "string", "format": "date"}),
(doc.Date, {"type": "string", "format": "date"}),
(doc.Date(), {"type": "string", "format": "date"}),
(datetime, {"type": "string", "format": "date-time"}),
(doc.DateTime, {"type": "string", "format": "date-time"}),
(doc.DateTime(), {"type": "string", "format": "date-time"}),
(TestSchema, {'$ref': '#/definitions/TestSchema', 'type': 'object'}),
(dict, {"type": "object", "properties": {}}),
({"foo": "bar"}, {"type": "object", "properties": {"foo": {}}}),
(list, {"type": "array", "items": []}),
(["foo", "bar"], {"type": "array", "items": {"description": ["foo", "bar"]}}),
],
)
def test_serialize_schema(schema, expected_schema):
serialized_schema = doc.serialize_schema(schema)

assert serialized_schema == expected_schema

0 comments on commit 43b4c9d

Please sign in to comment.