Esempio n. 1
0
def test_all(dummy_request):
    mapping = [
        (schema.Object(schema=IResource),
         serialize_schema_field.DefaultSchemaFieldSerializer),
        (schema.Text(),
         serialize_schema_field.DefaultTextSchemaFieldSerializer),
        (schema.TextLine(),
         serialize_schema_field.DefaultTextLineSchemaFieldSerializer),
        (schema.Float(),
         serialize_schema_field.DefaultFloatSchemaFieldSerializer),
        (schema.Int(), serialize_schema_field.DefaultIntSchemaFieldSerializer),
        (schema.Bool(),
         serialize_schema_field.DefaultBoolSchemaFieldSerializer),
        (schema.List(),
         serialize_schema_field.DefaultCollectionSchemaFieldSerializer),
        (schema.Choice(values=('one', 'two')),
         serialize_schema_field.DefaultChoiceSchemaFieldSerializer),
        (schema.Object(schema=IResource),
         serialize_schema_field.DefaultObjectSchemaFieldSerializer),
        (RichText(),
         serialize_schema_field.DefaultRichTextSchemaFieldSerializer),
        (schema.Date(),
         serialize_schema_field.DefaultDateSchemaFieldSerializer),
        (schema.Time(),
         serialize_schema_field.DefaultTimeSchemaFieldSerializer),
        (schema.Dict(),
         serialize_schema_field.DefaultDictSchemaFieldSerializer),
        (schema.Datetime(),
         serialize_schema_field.DefaultDateTimeSchemaFieldSerializer),
    ]
    container = Container()
    for field, klass in mapping:
        adapter = getMultiAdapter((field, container, dummy_request),
                                  interface=ISchemaFieldSerializeToJson)
        assert isinstance(adapter, klass)
Esempio n. 2
0
class ITestSchema(Interface):

    text = schema.TextLine()
    integer = schema.Int()
    floating = schema.Float()
    list_of_text = schema.List(value_type=schema.TextLine())
    tuple_of_text = schema.Tuple(value_type=schema.TextLine())
    set_of_text = schema.Set(value_type=schema.TextLine())
    frozenset_of_text = schema.FrozenSet(value_type=schema.TextLine())
    dict_value = schema.Dict(key_type=schema.TextLine(),
                             value_type=schema.TextLine())
    datetime = schema.Datetime()
    date = schema.Date()
    time = schema.Time()
Esempio n. 3
0
class ITestSchema(Interface):

    text = schema.TextLine(required=False)
    integer = schema.Int(required=False)
    floating = schema.Float(required=False)
    list_of_text = schema.List(value_type=schema.TextLine(), required=False)
    tuple_of_text = schema.Tuple(value_type=schema.TextLine(), required=False)
    set_of_text = schema.Set(value_type=schema.TextLine(), required=False)
    frozenset_of_text = schema.FrozenSet(value_type=schema.TextLine(),
                                         required=False)
    dict_value = schema.Dict(key_type=schema.TextLine(),
                             value_type=schema.TextLine(),
                             required=False)
    datetime = schema.Datetime(required=False)
    date = schema.Date(required=False)
    time = schema.Time(required=False)

    patch_list = fields.PatchField(
        schema.List(value_type=schema.Dict(key_type=schema.Text(),
                                           value_type=schema.Text()),
                    required=False))
    patch_dict = fields.PatchField(schema.Dict(key_type=schema.Text(),
                                               value_type=schema.Text()),
                                   required=False)

    bucket_list = fields.BucketListField(bucket_len=10,
                                         required=False,
                                         value_type=schema.Dict(
                                             key_type=schema.Text(),
                                             value_type=schema.Text()))

    datetime_bucket_list = fields.BucketListField(bucket_len=10,
                                                  required=False,
                                                  value_type=schema.Datetime())

    nested_patch = fields.PatchField(
        schema.Dict(required=False,
                    key_type=schema.Text(),
                    value_type=fields.PatchField(
                        schema.List(value_type=schema.Object(
                            schema=INestFieldSchema)))))
Esempio n. 4
0
class ITestSchema(Interface):

    text = schema.TextLine(required=False)
    integer = schema.Int(required=False)
    floating = schema.Float(required=False)
    list_of_text = schema.List(value_type=schema.TextLine(), required=False)
    tuple_of_text = schema.Tuple(value_type=schema.TextLine(), required=False)
    set_of_text = schema.Set(value_type=schema.TextLine(), required=False)
    frozenset_of_text = schema.FrozenSet(value_type=schema.TextLine(),
                                         required=False)
    dict_value = schema.Dict(key_type=schema.TextLine(),
                             value_type=schema.TextLine(),
                             required=False)
    datetime = schema.Datetime(required=False)
    date = schema.Date(required=False)
    time = schema.Time(required=False)

    patch_list = fields.PatchField(
        schema.List(value_type=schema.Dict(key_type=schema.Text(),
                                           value_type=schema.Text()),
                    required=False))
    patch_list_int = fields.PatchField(
        schema.List(value_type=schema.Int(), required=False))
    patch_dict = fields.PatchField(schema.Dict(key_type=schema.Text(),
                                               value_type=schema.Text()),
                                   required=False)

    patch_int = fields.PatchField(schema.Int(default=22), required=False)

    patch_int_no_default = fields.PatchField(schema.Int(), required=False)

    bucket_list = fields.BucketListField(
        bucket_len=10,
        required=False,
        value_type=schema.Dict(key_type=schema.Text(),
                               value_type=schema.Text()),
    )

    datetime_bucket_list = fields.BucketListField(bucket_len=10,
                                                  required=False,
                                                  value_type=schema.Datetime())

    union_field = schema.UnionField(schema.Datetime(),
                                    schema.Int(),
                                    required=False)
    union_field_obj = schema.UnionField(schema.Object(IObjectA),
                                        schema.Object(schema=IObjectB),
                                        required=False)

    nested_patch = fields.PatchField(
        schema.Dict(
            required=False,
            key_type=schema.Text(),
            value_type=fields.PatchField(
                schema.List(value_type=schema.Object(
                    schema=INestFieldSchema))),
        ))

    dict_of_obj = schema.Dict(
        required=False,
        key_type=schema.Text(),
        value_type=schema.Object(schema=INestFieldSchema))

    patch_dict_of_obj = fields.PatchField(
        schema.Dict(required=False,
                    key_type=schema.Text(),
                    value_type=schema.Object(schema=INestFieldSchema)))

    patch_tuple = fields.PatchField(
        schema.Tuple(required=False,
                     value_type=schema.Text(schema=INestFieldSchema)))

    bucket_dict = fields.BucketDictField(bucket_len=10,
                                         required=False,
                                         key_type=schema.Text(),
                                         value_type=schema.Text())