Exemplo n.º 1
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
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
0
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",
                        mocked=mocked,
Exemplo n.º 5
0
import json

from pjxxs import fields, loader

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", nullable=True))
    inner_mocked.schema.add_field(
        fields.Array("inner_mocked_array", allowed_values=["INNER", "MOCKED"]))
    mocked.schema.add_field(
        fields.SchemaType("inner_mocked_ref", "inner_mocked"))


class TestLoadFromJson(unittest.TestCase):