def setUp(self): import datetime phone = model.Phone('408-444-4444', 'Hogeyama Hogeo', '1400 Fashion Island', '650-666-6666', datetime.datetime(1960,1,1)) from jsonpickle import Pickler p = Pickler() ser = p.flatten(phone) mc = memcache.Client([config['app_conf']['memcachedb.servers']], debug = 0) mc.set(phone.id, ser) self._id = phone.id
def test_pickle_json_includes_class_attributes(self): @dataclass class TestEventClassAttributes(BaseEvent): type = 'ai.anagon.base' sub_type = 'ai.anagon.child' content: str self.assertEqual( { 'type': 'ai.anagon.base', 'sub_type': 'ai.anagon.child', 'content': 'test', }, Pickler(unpicklable=False).flatten( TestEventClassAttributes("test")))
def test_save_invalid_class_data(self): """Tests that a 404 response is returned if it tried to save non Phone class data""" class Hoge(): pass mc = memcache.Client([config['app_conf']['memcachedb.servers']], debug = 0) h = Hoge() p = Pickler() ser = p.flatten(h) key = uuid.uuid4().hex mc.set(key, ser) response = self.app.post( url = url_for(controller = 'phone', action = 'save', id = key), params = {'mobile_number': u'000-0000-0000', 'name': u'name name', 'address': u'the address', 'home_number': u'111-1111-1111', 'dob': u'2000/01/01'}, status = 404)
def _get_serialized_context(state: BotState, context: TurnContext): ctx = state.get(context) return Pickler(unpicklable=False).flatten(ctx)
def print_json(self, event: MathParsed): print(Pickler().flatten(event))