def test_runHandler(self): from StringIO import StringIO json=u'{"method":"echo","params":["foobar"], "id":""}' fin=StringIO(json) fout=StringIO() req = ApacheRequestMockup(__file__ , fin, fout) jsonrpc.handler(req) data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), {"result":"foobar", "error":None, "id":""})
def test_mod_python_handler(self): json = b'{"method":"echo","params":["foobar"], "id":""}' fin = BytesIO(json) fout = BytesIO() req = ApacheRequestMockup(__file__, fin, fout) jsonrpc.handler(req) data = fout.getvalue() expect = { 'result': 'foobar', 'jsonrpc': '2.0', 'id': '', } actual = jsonrpc.loads(data) self.assertEqual(expect, actual)
def test_mod_python_handler(self): json = '{"method":"echo","params":["foobar"], "id":""}' fin = StringIO(json) fout = StringIO() req = ApacheRequestMockup(__file__ , fin, fout) jsonrpc.handler(req) data = fout.getvalue() expect = { 'result': 'foobar', 'jsonrpc': '2.0', 'id': '', } actual = jsonrpc.loads(data) self.assertEquals(expect, actual)
def test_mod_python_handler(self): from StringIO import StringIO json=u'{"method":"echo","params":["foobar"], "id":""}' fin=StringIO(json) fout=StringIO() req = ApacheRequestMockup(__file__ , fin, fout) jsonrpc.handler(req) data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), {'result': 'foobar', 'jsonrpc': '2.0', 'id': ''})
def test_runHandler(self): from StringIO import StringIO json = u'{"method":"echo","params":["foobar"], "id":""}' fin = StringIO(json) fout = StringIO() req = ApacheRequestMockup(__file__, fin, fout) jsonrpc.handler(req) data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), { "result": "foobar", "error": None, "id": "" })
def test_mod_python_handler(self): from StringIO import StringIO json = u'{"method":"echo","params":["foobar"], "id":""}' fin = StringIO(json) fout = StringIO() req = ApacheRequestMockup(__file__, fin, fout) jsonrpc.handler(req) data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), { 'result': 'foobar', 'jsonrpc': '2.0', 'id': '' })
def test_ServiceImplementationNotFound(self): from StringIO import StringIO json=u'{"method":"echo","params":["foobar"], "id":""}' fin=StringIO(json) fout=StringIO() req = ApacheRequestMockup("foobar" , fin, fout) rslt = jsonrpc.handler(req) self.assertEquals(rslt, "OK") data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), {u'id': '', u'result': None, u'error': {u'message': '', u'name': u'ServiceImplementaionNotFound'}} )
def test_service_implementation_not_found(self): from StringIO import StringIO json=u'{"method":"echo","params":["foobar"], "id":""}' fin=StringIO(json) fout=StringIO() req = ApacheRequestMockup('foobar', fin, fout) rslt = jsonrpc.handler(req) self.assertEquals(rslt, 'OK') data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), {u'id': '', u'error': { u'message': 'Method not found', u'code': -32601}})
def test_service_implementation_not_found(self): from StringIO import StringIO json = u'{"method":"echo","params":["foobar"], "id":""}' fin = StringIO(json) fout = StringIO() req = ApacheRequestMockup('foobar', fin, fout) rslt = jsonrpc.handler(req) self.assertEquals(rslt, 'OK') data = fout.getvalue() self.assertEquals(jsonrpc.loads(data), { u'id': '', u'error': { u'message': 'Method not found', u'code': -32601 } })
def test_service_implementation_not_found(self): json = b'{"method":"echo","params":["foobar"], "id":""}' fin = BytesIO(json) fout = BytesIO() req = ApacheRequestMockup('foobar', fin, fout) rslt = jsonrpc.handler(req) self.assertEqual(rslt, 'OK') data = fout.getvalue() expect = { 'id': '', 'error': { 'message': 'Method not found', 'code': -32601 } } actual = jsonrpc.loads(data) self.assertEqual(expect, actual)
def test_service_echoes_unicode(self): echo_data = {'hello': uchr(0x1234)} json = jsonrpc.dumps({ 'id': '', 'params': [echo_data], 'method': 'echo' }) fin = BytesIO(encode(json)) fout = BytesIO() req = ApacheRequestMockup(__file__, fin, fout) result = jsonrpc.handler(req) self.assertEqual(result, 'OK') data = fout.getvalue() expect = echo_data actual = jsonrpc.loads(data)['result'] self.assertEqual(expect, actual)
def test_service_echoes_unicode(self): echo_data = {'hello': unichr(0x1234)} json = jsonrpc.dumps({ 'id': '', 'params': [echo_data], 'method': 'echo', }) fin=StringIO(json) fout=StringIO() req = ApacheRequestMockup(__file__, fin, fout) result = jsonrpc.handler(req) self.assertEquals(result, 'OK') data = fout.getvalue() expect = echo_data actual = jsonrpc.loads(data)['result'] self.assertEqual(expect, actual)
def test_ServiceImplementationNotFound(self): from StringIO import StringIO json = u'{"method":"echo","params":["foobar"], "id":""}' fin = StringIO(json) fout = StringIO() req = ApacheRequestMockup("foobar", fin, fout) rslt = jsonrpc.handler(req) self.assertEquals(rslt, "OK") data = fout.getvalue() self.assertEquals( jsonrpc.loads(data), { u'id': '', u'result': None, u'error': { u'message': '', u'name': u'ServiceImplementaionNotFound' } })