Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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'})
"""
Checks that the elements in a group of concepts or collections are not the
the group itself, that they actually exist and are within
the same conceptscheme.
"""
for member_concept_id in members:
if member_concept_id == collection_id:
errors.append(colander.Invalid(
node_location,
'A concept or collection cannot be related to itself'
))
return False
try:
skos_manager.get_thing(member_concept_id, conceptscheme_id)
except NoResultFound:
errors.append(colander.Invalid(
node_location,
'Concept not found, check concept_id. Please be aware members should be within one scheme'
))
return False
return True
def _assert_follows_last_version(node: colander.SchemaNode, value: list,
last: object):
follows = value[0]
if follows is not last:
last_path = resource_path(last)
msg = 'No fork allowed - valid follows resources are: {0}'
msg = msg.format(str(last_path))
raise colander.Invalid(node, msg, value=value)
def validator(node, value):
invoice = Invoice.get(value)
company_subaccount = get_company_subaccount(invoice.account.id)
if not company_subaccount:
raise colander.Invalid(
node,
_(u'Create company subaccount for account from invoice'),
)
stored as references. If object requires no datafiles and does not
need to read references from a \*.json file in saveloc, then this
can be None.
:param references: references object - if this is called by the Model,
it will pass a references object. It is not required.
:returns: object constructed from json_data.
'''
references = (references, References())[references is None]
ref_dict = cls._load_refs(json_data, saveloc, references)
cls._update_datafile_path(json_data, saveloc)
# deserialize after removing references
try:
_to_dict = cls.deserialize(json_data)
except colander.Invalid as e:
print('Class {0} failed to deserialize.'.format(cls.__name__))
raise e
if ref_dict:
_to_dict.update(ref_dict)
c_fields = cls._state.get_field_by_attribute('iscollection')
for field in c_fields:
_to_dict[field.name] = cls._load_collection(saveloc,
_to_dict[field.name],
references)
obj = cls.new_from_dict(_to_dict)
return obj
def privacy_acceptance_validator(node, value):
'''Colander validator that ensures privacy acceptance checkbox checked'''
if value is False:
msg = _("Acceptance of the privacy policy is required")
raise colander.Invalid(node, msg)
def validate_deep(data, context, direction, attribute):
relations = []
node = sequence(direction)
inv = Invalid(node)
for i, relation_data in enumerate(data.get(direction, [])):
try:
other = relation_data.get(attribute, {})
schema = context.network.get_relation_schema(relation_data.get('type'))
if schema is None:
raise Invalid(node, "Invalid relation type: %e" % relation_data.get('type'))
relation = validate_relation(relation_data, schema, context, ignore_entities=True)
schema = context.network.get_entity_schema(other.get('type'))
if schema is None:
raise Invalid(node, "Invalid entity type: %e" % other.get('type'))
relation[attribute] = validate_entity(other, schema, context, deep=False)
relations.append(relation)
except Invalid as sub:
inv.add(sub, i)
def deserialize_update(self, cstruct):
error = None
schema = self.__schema__
appstruct = {}
for i, (name, value) in enumerate(cstruct.items()):
node = schema[name]
try:
appstruct[name] = node.deserialize(value)
except colander.Invalid, e:
if error is None:
error = colander.Invalid(schema)
error.add(e, i)
if error is not None:
raise error
self._update_from_dict(appstruct, skip_missing=True)
def validate_permission_name(node, value):
permission_name = value[0]
if permission_name not in registry.content.permissions():
msg = 'No such permission: {0}'.format(permission_name)
raise Invalid(node, msg, value=permission_name)
def validate_user_is_active(node: SchemaNode, value: dict):
user = request.validated.get('user', None)
if user is None:
return
elif not user.active:
error = Invalid(node)
error.add(Invalid(node[child_node_name],
msg='User account not yet activated'))
raise error
return validate_user_is_active