Exemplo n.º 1
0
    def test_invalid(schemas, exception):
        """
        GIVEN invalid schema and expected exception
        WHEN _get_schema is called with the schema
        THEN the expected exception is raised.
        """
        name = "Schema"

        with pytest.raises(exception):
            model_factory._get_schema(name, schemas)
Exemplo n.º 2
0
    def test_valid_inherits(inherits):
        """
        GIVEN valid schema that inherits
        WHEN _get_schema is called with the schema
        THEN the schema exclusing the parent is returned.
        """
        name = "Schema"
        schema = {
            "allOf": [
                {
                    "type": "object",
                    "x-inherits": inherits,
                    "properties": {"key": "value"},
                },
                {"$ref": "#/components/schemas/RefSchema"},
            ]
        }
        ref_schema = {
            "x-tablename": "schema",
            "type": "object",
            "properties": {"parent_key": "parent value"},
        }
        schemas = {"Schema": schema, "RefSchema": ref_schema}

        returned_schema = model_factory._get_schema(name, schemas)

        assert returned_schema == {
            "type": "object",
            "x-inherits": "RefSchema",
            "properties": {"key": "value"},
        }
Exemplo n.º 3
0
    def test_valid():
        """
        GIVEN valid schema
        WHEN _get_schema is called with the schema
        THEN the schema is returned.
        """
        name = "Schema"
        schema = {
            "type": "object",
            "x-tablename": "schema",
            "properties": {"key": "value"},
        }
        schemas = {
            "Schema": {"$ref": "#/components/schemas/RefSchema"},
            "RefSchema": schema,
        }

        returned_schema = model_factory._get_schema(name, schemas)

        assert returned_schema == schema