async def test_handled_exception(container_requester): async with container_requester as requester: with mock.patch("guillotina.asgi.Guillotina.request_handler") as handle_mock: # noqa f = asyncio.Future() f.set_result(None) handle_mock.return_value = f handle_mock.side_effect = DeserializationError([{"err": "bad error"}]) _, status = await requester("GET", "/db") assert status == 412
async def __call__( self, data: Dict[str, Any], validate_all: bool = False, ignore_errors: bool = False, create: bool = False, ) -> IResource: errors: List[Dict[str, Any]] = [] # do behavior first in case they modify context values for behavior_schema, behavior in await get_all_behaviors(self.context, load=False): dotted_name = behavior_schema.__identifier__ if dotted_name not in data: # syntax {"namespace.IBehavior": {"foo": "bar"}} # we're not even patching this behavior if no iface found in payload if create: # signal to caching engine to cache no data here so # we prevent a future lookup try: txn = self.context.__txn__ await txn._cache.set( _EMPTY, container=self.context, id=behavior.__annotations_data_key__, variant="annotation", ) except AttributeError: pass continue if IAsyncBehavior.implementedBy(behavior.__class__): # providedBy not working here? await behavior.load(create=True) await self.set_schema(behavior_schema, behavior, data, errors, validate_all, True) factory = get_cached_factory(self.context.type_name) main_schema = factory.schema await self.set_schema(main_schema, self.context, data, errors, validate_all, False) if errors and not ignore_errors: raise DeserializationError(errors) return self.context
def test_deserialization_error_formats_error(): error = DeserializationError([{ "error": "Foobar", "field": "foobar_field" }]) assert "foobar_field" in str(error)
def test_deserialization_error_formats_error(): error = DeserializationError([{ 'error': 'Foobar', 'field': 'foobar_field' }]) assert 'foobar_field' in str(error)