def testSerializeContextSansOps(self): context, _ = robot_abstract.ParseJSONBody(DEBUG_DATA) serialized = robot_abstract.SerializeContext(context) self.assertEqual( '{"operations": {"javaClass": "java.util.ArrayList", "list": []}, ' '"javaClass": "com.google.wave.api.impl.OperationMessageBundle"}', serialized)
def post(self): """Handles HTTP POST requests.""" json_body = self.request.body if not json_body: # TODO(davidbyttow): Log error? return json_body = unicode(json_body, 'utf8') logging.info('Incoming: ' + json_body) context, events = robot_abstract.ParseJSONBody(json_body) for event in events: try: self._robot.HandleEvent(event, context) except: logging.error(traceback.format_exc()) json_response = robot_abstract.SerializeContext( context, self._robot.version) logging.info('Outgoing: ' + json_response) # Build the response. self.response.headers[ 'Content-Type'] = 'application/json; charset=utf-8' self.response.out.write(json_response.encode('utf-8'))
def testSerializeContextWithOps(self): context, _ = robot_abstract.ParseJSONBody(DEBUG_DATA) wavelet = context.GetWavelets()[0] blip = context.GetBlipById(wavelet.GetRootBlipId()) blip.GetDocument().SetText('Hello, wave!') serialized = robot_abstract.SerializeContext(context) self.assertEqual( '{"operations": {"javaClass": "java.util.ArrayList", "list": [' '{"blipId": "wdykLROk*13", "index": -1, "waveletId": "conv+root", "javaClass": "com.google.wave.api.impl.OperationImpl", "waveId": "wdykLROk*11", "property": {"javaClass": "com.google.wave.api.Range", "end": 1, "start": 0}, "type": "DOCUMENT_DELETE"}, ' '{"blipId": "wdykLROk*13", "index": 0, "waveletId": "conv+root", "javaClass": "com.google.wave.api.impl.OperationImpl", "waveId": "wdykLROk*11", "property": "Hello, wave!", "type": "DOCUMENT_INSERT"}' ']}, "javaClass": "com.google.wave.api.impl.OperationMessageBundle"}', serialized)
def testSerializeContextWithOps2(self): context, _ = robot_abstract.ParseJSONBody(DEBUG_DATA) wavelet = context.GetRootWavelet() wavelet.CreateBlip().GetDocument().SetText("Hello there!") serialized = robot_abstract.SerializeContext(context, '1') expected_json = ( '{"operations": {"javaClass": "java.util.ArrayList", "list": [' '{"blipId": "", "index": -1, "waveletId": "test.com!conv+root", "javaClass": "com.google.wave.api.impl.OperationImpl", "waveId": "test.com!wdykLROk*11", "property": {"blipId": "TBD_test.com!conv+root_1", "javaClass": "com.google.wave.api.impl.BlipData", "waveId": "test.com!wdykLROk*11", "waveletId": "test.com!conv+root"}, "type": "WAVELET_APPEND_BLIP"}, ' '{"blipId": "TBD_test.com!conv+root_1", "index": -1, "waveletId": "test.com!conv+root", "javaClass": "com.google.wave.api.impl.OperationImpl", "waveId": "test.com!wdykLROk*11", "type": "DOCUMENT_DELETE"}, ' '{"blipId": "TBD_test.com!conv+root_1", "index": 0, "waveletId": "test.com!conv+root", "javaClass": "com.google.wave.api.impl.OperationImpl", "waveId": "test.com!wdykLROk*11", "property": "Hello there!", "type": "DOCUMENT_INSERT"}' ']}, "javaClass": "com.google.wave.api.impl.OperationMessageBundle", "version": "1"}' ) self.assertEqual(expected_json, serialized)
def testParseJSONBody(self): context, events = robot_abstract.ParseJSONBody(DEBUG_DATA) # Test some basic properties; the rest should be covered by # ops.CreateContext. blips = context.GetBlips() self.assertEqual(1, len(blips)) self.assertEqual('wdykLROk*13', blips[0].GetId()) self.assertEqual('wdykLROk*11', blips[0].GetWaveId()) self.assertEqual('conv+root', blips[0].GetWaveletId()) self.assertEqual(1, len(events)) event = events[0] self.assertEqual('WAVELET_PARTICIPANTS_CHANGED', event.type) self.assertEqual( { 'participantsRemoved': [], 'participantsAdded': ['*****@*****.**'] }, event.properties)