def output(self, key, obj): try: data = fields.to_marshallable_type(obj) entity = dbs.query(Entity).filter(Entity.id == data["id"]).filter(Entity.confirmed).first() if not entity: raise fields.MarshallingException() endpoint = entity.type o = urlparse(url_for(endpoint, _external=self.absolute, **data)) if self.absolute: scheme = self.scheme if self.scheme is not None else o.scheme return urlunparse((scheme, o.netloc, o.path, "", "", "")) return urlunparse(("", "", o.path, "", "", "")) except TypeError as te: raise fields.MarshallingException(te)
def test_to_dict_custom_marshal(self): obj = {"hey": 3} self.assertEquals(obj, fields.to_marshallable_type(Bar()))
def test_to_dict_obj(self): obj = {"hey": 3} self.assertEquals(obj, fields.to_marshallable_type(Foo()))
def test_to_dict(self): obj = {"hey": 3} self.assertEqual(obj, fields.to_marshallable_type(obj))