Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _makeSchema(self, name='schema'):
import colander
integer = colander.SchemaNode(
colander.Integer(),
name='int',
validator=colander.Range(0, 10)
)
ob = colander.SchemaNode(
colander.GlobalObject(package=colander),
name='ob',
)
tup = colander.SchemaNode(
colander.Tuple(),
colander.SchemaNode(
colander.Integer(),
name='tupint',
),
def generate_colander():
class User(colander.MappingSchema):
id = colander.SchemaNode(colander.Integer(),
missing=colander.drop)
email = colander.SchemaNode(colander.String(),
validator=colander.Email())
second_email = colander.SchemaNode(colander.String(),
validator=colander.Email(),
missing=colander.null)
return User()
def test_deserialize_invalid_action(self):
inst = self._make_one()
with pytest.raises(colander.Invalid):
inst.deserialize({'action': 'blah', 'resource': self.request.application_url + '/child'})
@foobar.post(schema=RequestSchema(), validators=(colander_validator,))
def foobar_post(request):
return {"test": "succeeded"}
class StringSequence(SequenceSchema):
_ = SchemaNode(String())
class ListQuerystringSequence(MappingSchema):
field = StringSequence()
def deserialize(self, cstruct):
if 'field' in cstruct and not isinstance(cstruct['field'], list):
cstruct['field'] = [cstruct['field']]
return MappingSchema.deserialize(self, cstruct)
class QSSchema(MappingSchema):
querystring = ListQuerystringSequence()
@foobaz.get(schema=QSSchema(), validators=(colander_validator,))
def foobaz_get(request):
return {"field": request.validated['querystring']['field']}
class NewsletterSchema(MappingSchema):
email = SchemaNode(String(), validator=Email(), missing=drop)
class RefererSchema(MappingSchema):
ref = SchemaNode(Integer(), missing=drop)
class NewsletterPayload(MappingSchema):
body = NewsletterSchema()
querystring = RefererSchema()
def test_deserialize_null(self):
import colander
typ = self._makeOne()
node = DummySchemaNode(None)
result = typ.deserialize(node, colander.null)
self.assertEqual(result, colander.null)
def _makeOne(self, min=None, max=None):
from colander import Length
return Length(min=min, max=max)
def setUp(self):
import colander
import limone
class NSAData(colander.Schema):
serialnum = colander.SchemaNode(colander.Str('UTF-8'))
date_of_contact = colander.SchemaNode(colander.Date())
class PersonalData(colander.Schema):
nsa_data = NSAData()
n_arrests = colander.SchemaNode(colander.Int())
class PersonSchema(colander.Schema):
name = colander.SchemaNode(colander.Str('UTF-8'))
age = colander.SchemaNode(colander.Integer(), default=500)
personal = PersonalData()
self.content_type = limone.make_content_type(PersonSchema, 'Person')
def _makeOne(self, wrapped):
from colander import deferred
return deferred(wrapped)
def schema_type():
return colander.Mapping(unknown='preserve')
def sheet_meta(sheet_meta):
from adhocracy_core.sheets import AnnotationStorageSheet
from adhocracy_core.interfaces import ISheet
class SheetASchema(colander.MappingSchema):
count = colander.SchemaNode(colander.Int(),
missing=colander.drop,
default=0)
meta = sheet_meta._replace(isheet=ISheet,
schema_class=SheetASchema,
sheet_class=AnnotationStorageSheet,
readable=True,
editable=True,
creatable=True)
return meta