Example #1
0
    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":""})
Example #2
0
    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': ''})
Example #5
0
    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": ""
        })
Example #6
0
    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': ''
        })
Example #7
0
    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}})
Example #9
0
    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
            }
        })
Example #10
0
    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)
Example #11
0
    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)
Example #13
0
    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'
                }
            })