示例#1
0
    def test_inner_schema(self):
        with patch.dict("sys.modules",
                        mocked=mocked,
                        inner_mocked=inner_mocked):
            schema = fields.Schema("test")
            schema.add_field(
                fields.SchemaType("level_1", mocked_mod_name, required=True))
            result = schema.to_json(**json_params)

            expected = {
                "@id": "test",
                "@version": 0,
                "level_1": {
                    "@properties": {
                        "nullable": False,
                        "allowed_types": ["dict"],
                        "allowed_values": [],
                        "field_type": "Schema:mocked",
                        "required": True
                    },
                    "inner_mocked_ref": {
                        "@properties": {
                            "nullable": False,
                            "allowed_types": ["dict"],
                            "allowed_values": [],
                            "field_type": "Schema:inner_mocked",
                            "required": False
                        },
                        "inner_mocked_object": {
                            "@properties": {
                                "nullable": False,
                                "allowed_types": ["dict"],
                                "allowed_values": [],
                                "field_type": "Object",
                                "required": False
                            }
                        }
                    },
                    "mocked_enum": {
                        "@properties": {
                            "nullable": False,
                            "allowed_types": ["str"],
                            "allowed_values": ["ONE", "TWO"],
                            "field_type": "Enum",
                            "required": True
                        }
                    },
                    "mocked_object": {
                        "@properties": {
                            "nullable": False,
                            "allowed_types": ["dict"],
                            "allowed_values": [],
                            "field_type": "Object",
                            "required": False
                        }
                    }
                }
            }
            assert_equal(result, json.dumps(expected, **json_params), "schema")
示例#2
0
	def _build(self, columns):
		schema_id = "%s/%s" % (
			self._record.table_schema, self._record.table_name
		)
		schema = fields.Schema(schema_id)
		for r in columns:
			column = SchemaColumn(self._conn, r)
			field = column.build()
			schema.add_field(field)
		return schema
示例#3
0
 def setUp(self):
     with patch.dict("sys.modules",
                     mocked=mocked,
                     inner_mocked=inner_mocked):
         schema = fields.Schema("test")
         obj = fields.Object("object_field", required=True)
         obj.add_field(fields.Object("object_field_inner", nullable=True))
         obj.add_field(
             fields.Array("object_field_inner_array",
                          nullable=True,
                          allowed_types=[str, int],
                          allowed_values=["value", 1, 2, 3]))
         schema.add_field(obj)
         self.schema = schema
示例#4
0
 def setUp(self):
     schema = fields.Schema("main/schema", 1)
     schema.add_field(fields.Array("array_1", required=True))
     schema.add_field(fields.Array("array_2", default=[]))
     schema.add_field(
         fields.Array(
             "array_3",
             nullable=True,
             required=True,
             allowed_types=[str, int],
             allowed_values=["one", "two", 543],
             default=[],
         ))
     self.schema = schema
示例#5
0
 def setUp(self):
     schema = fields.Schema("main/schema", 1)
     obj_1 = fields.Object("object_1", required=True)
     obj_2 = fields.Object("object_2", nullable=True)
     obj_2.add_field(
         fields.Array("obj2_arr", nullable=True, allowed_types=[int, dict]))
     obj_3 = fields.Object("object_3", nullable=True)
     obj_3.add_field(
         fields.Object("obj_3_inner_1",
                       required=True,
                       default={},
                       nullable=False))
     schema.add_field(obj_1)
     schema.add_field(obj_2)
     schema.add_field(obj_3)
     self.schema = schema
示例#6
0
 def setUp(self):
     with patch.dict("sys.modules",
                     mocked=mocked,
                     inner_mocked=inner_mocked):
         schema = fields.Schema("test")
         schema.add_field(fields.String("string_field"))
         schema.add_field(fields.Int("int_field", nullable=True))
         obj = fields.Object("obj")
         obj.add_field(
             fields.SchemaType("level_1", mocked_mod_name, required=True))
         inner_object = fields.Object("inner_object", required=True)
         inner_object.add_field(
             fields.Object("inner_inner_object", required=True))
         obj.add_field(inner_object)
         inner_array = fields.Array("inner_array", allowed_types=[str, int])
         inner_array.append(fields.String("")).append(fields.Array(""))
         obj.add_field(inner_array).add_field(fields.String("inner_field"))
         arr = fields.Array("array")
         arr.append(fields.String(""), fields.Int(""), fields.Bool(""),
                    fields.Double(""))
         schema.add_field(arr)
         schema.add_field(obj)
         self.schema = schema
示例#7
0
	def setUp(self):
		schema = fields.Schema("main/schema", 1)
		schema.add_field(fields.Int("non-nullable", required=True))
		schema.add_field(fields.Int("nullable", nullable=True))
		self.schema = schema
示例#8
0
文件: manager.py 项目: mcptr/pjxxs
 def __init__(self, path):
     self.__path = path
     self._schema_inst = fields.Schema(self.ident())
     self.reload()
示例#9
0
文件: post.py 项目: mcptr/bbone-js-py
from pjxxs import fields

schema = fields.Schema("post", 1)
schema.add_field(fields.String("title", required=True))
示例#10
0
import json

from pjxxs import fields

json_params = {
    "sort_keys": True,
    "indent": 4,
}

mocked_mod_name = "mocked"
mocked = MagicMock()

inner_mocked = MagicMock()

with patch.dict("sys.modules", mocked=mocked, inner_mocked=inner_mocked):
    mocked.schema = fields.Schema("mocked", 1)
    mocked.schema.add_field(fields.Object("mocked_object"))
    mocked.schema.add_field(
        fields.Enum("mocked_enum",
                    required=True,
                    allowed_values=["ONE", "TWO"]))

    inner_mocked.schema = fields.Schema("inner_mocked", 1)
    inner_mocked.schema.add_field(fields.Object("inner_mocked_object"))
    mocked.schema.add_field(
        fields.SchemaType("inner_mocked_ref", "inner_mocked"))


class TestValidation(unittest.TestCase):
    def setUp(self):
        with patch.dict("sys.modules",
示例#11
0
 def setUp(self):
     with patch.dict("sys.modules", mocked=mocked):
         schema = fields.Schema("main/schema", 1)
         schema.add_field(
             fields.SchemaType("level_1", mocked_mod_name, required=True))
         self.schema = schema
示例#12
0
import sys
import unittest
from unittest.mock import MagicMock, patch
from nose.tools import assert_true
from nose.tools import assert_false
from pjxxs import fields

mocked_mod_name = "mocked"
mocked = MagicMock()
inner_mocked = MagicMock()
inner_mocked.schema = fields.Schema("inner_mocked", 1)
inner_mocked.schema.add_field(fields.Object("inner_object"))
inner_mocked.schema.add_field(
    fields.Enum("inner_enum", required=True, allowed_values=["ONE", "TWO"]))

with patch.dict("sys.modules", mocked=mocked, inner_mocked=inner_mocked):
    mocked.schema = fields.Schema(mocked_mod_name, 1)
    mocked.schema.add_field(fields.Object("mocked_object"))
    mocked.schema.add_field(
        fields.SchemaType("inner_mocked", "inner_mocked", nullable=False))


class TestValidation(unittest.TestCase):
    def setUp(self):
        with patch.dict("sys.modules", mocked=mocked):
            schema = fields.Schema("main/schema", 1)
            schema.add_field(
                fields.SchemaType("level_1", mocked_mod_name, required=True))
            self.schema = schema
            # print("\nDUMP", self.schema.to_json(sort_keys=True, indent=4))
示例#13
0
 def setUp(self):
     schema = fields.Schema("main/schema", 1)
     # required should be forced to not required.
     schema.add_field(fields.Null("required", required=True))
     schema.add_field(fields.Null("not-required"))
     self.schema = schema