Exemplo n.º 1
0
    def test_jsonrequests(self):
        data = '{"params":[],"method":"system.listMethods","id":123}'
        response = self.client.post(self.rpc_path, data, 'application/json')
        self.assertEqual(response.status_code, 200)
        jsondict = json.loads(response.content)
        self.assertTrue(jsondict['error'] is None)
        self.assertEqual(jsondict['id'], 123)
        self.assertTrue(isinstance(jsondict['result'], list))

        data = '{"params":[],"method":"system.describe","id":456}'
        response = self.client.post(self.rpc_path, data, 'text/javascript')
        self.assertEqual(response.status_code, 200)
        jsondict = json.loads(response.content)
        self.assertTrue(jsondict['error'] is None)
        self.assertEqual(jsondict['id'], 456)
        self.assertTrue(isinstance(jsondict['result'], dict))
Exemplo n.º 2
0
 def test_jsonrequests(self):
     data = '{"params":[],"method":"system.listMethods","id":123}'
     response = self.client.post(self.rpc_path, data, 'application/json')
     self.assertEqual(response.status_code, 200)
     jsondict = json.loads(response.content)
     self.assertTrue(jsondict['error'] is None)
     self.assertEqual(jsondict['id'], 123)
     self.assertTrue(isinstance(jsondict['result'], list))
     
     data = '{"params":[],"method":"system.describe","id":456}'
     response = self.client.post(self.rpc_path, data, 'text/javascript')
     self.assertEqual(response.status_code, 200)
     jsondict = json.loads(response.content)
     self.assertTrue(jsondict['error'] is None)
     self.assertEqual(jsondict['id'], 456)
     self.assertTrue(isinstance(jsondict['result'], dict))
Exemplo n.º 3
0
    def test_typedetection(self):
        data = '{"params":[],"method":"system.listMethods","id":123}'
        response = self.client.post(self.rpc_path, data, 'text/plain')
        self.assertEqual(response.status_code, 200)
        jsondict = json.loads(response.content)
        self.assertTrue(jsondict['error'] is None)
        self.assertEqual(jsondict['id'], 123)
        self.assertTrue(isinstance(jsondict['result'], list))

        data = '<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>'
        response = self.client.post(self.rpc_path, data, 'text/plain')
        self.assertEqual(response.status_code, 200)
        xmlrpclib.loads(
            response.content)  # this will throw an exception with bad data

        # jsonrpc request with xmlrpc data (should be error)
        data = '<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>'
        response = self.client.post(self.rpc_path, data, 'application/json')
        self.assertEqual(response.status_code, 200)
        jsondict = json.loads(response.content)
        self.assertTrue(jsondict['result'] is None)
        self.assertEqual(jsondict['id'], '')
        self.assertTrue(isinstance(jsondict['error'], dict))

        data = '{"params":[],"method":"system.listMethods","id":123}'
        try:
            response = self.client.post(self.rpc_path, data, 'text/xml')
        except:
            # for some reason, this throws an expat error
            # but only in python 2.4
            return
        self.assertEqual(response.status_code, 200)
        try:
            xmlrpclib.loads(response.content)
            self.fail('parse error expected')
        except xmlrpclib.Fault:
            pass
Exemplo n.º 4
0
 def test_typedetection(self):
     data = '{"params":[],"method":"system.listMethods","id":123}'
     response = self.client.post(self.rpc_path, data, 'text/plain')
     self.assertEqual(response.status_code, 200)
     jsondict = json.loads(response.content)
     self.assertTrue(jsondict['error'] is None)
     self.assertEqual(jsondict['id'], 123)
     self.assertTrue(isinstance(jsondict['result'], list))
     
     data = '<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>'
     response = self.client.post(self.rpc_path, data, 'text/plain')
     self.assertEqual(response.status_code, 200)
     xmlrpclib.loads(response.content)       # this will throw an exception with bad data
     
     # jsonrpc request with xmlrpc data (should be error)
     data = '<?xml version="1.0"?><methodCall><methodName>system.listMethods</methodName><params></params></methodCall>'
     response = self.client.post(self.rpc_path, data, 'application/json')
     self.assertEqual(response.status_code, 200)
     jsondict = json.loads(response.content)
     self.assertTrue(jsondict['result'] is None)
     self.assertEqual(jsondict['id'], '')
     self.assertTrue(isinstance(jsondict['error'], dict))
     
     data = '{"params":[],"method":"system.listMethods","id":123}'
     try:
         response = self.client.post(self.rpc_path, data, 'text/xml')
     except:
         # for some reason, this throws an expat error
         # but only in python 2.4
         return
     self.assertEqual(response.status_code, 200)
     try:
         xmlrpclib.loads(response.content)
         self.fail('parse error expected')
     except xmlrpclib.Fault:
         pass
Exemplo n.º 5
0
    def test_badrequests(self):
        data = '{"params":[],"method":"system.methodHelp","id":456}'
        response = self.client.post(self.rpc_path, data, 'application/json')
        self.assertEqual(response.status_code, 200)
        jsondict = json.loads(response.content)
        self.assertTrue(jsondict['error'] is not None)
        self.assertEqual(jsondict['id'], 456)
        self.assertTrue(jsondict['result'] is None)
        self.assertEqual(jsondict['error']['code'], JSONRPC_SERVICE_ERROR)

        data = '<?xml version="1.0"?><methodCall><methodName>method.N0t.Exists</methodName><params></params></methodCall>'
        response = self.client.post(self.rpc_path, data, 'text/xml')
        self.assertEqual(response.status_code, 200)
        try:
            xmlrpclib.loads(response.content)
            self.fail('parse error expected')
        except xmlrpclib.Fault, fault:
            self.assertEqual(fault.faultCode, 1)
Exemplo n.º 6
0
 def test_badrequests(self):
     data = '{"params":[],"method":"system.methodHelp","id":456}'
     response = self.client.post(self.rpc_path, data, 'application/json')
     self.assertEqual(response.status_code, 200)
     jsondict = json.loads(response.content)
     self.assertTrue(jsondict['error'] is not None)
     self.assertEqual(jsondict['id'], 456)
     self.assertTrue(jsondict['result'] is None)
     self.assertEqual(jsondict['error']['code'], JSONRPC_SERVICE_ERROR)
     
     data = '<?xml version="1.0"?><methodCall><methodName>method.N0t.Exists</methodName><params></params></methodCall>'
     response = self.client.post(self.rpc_path, data, 'text/xml')
     self.assertEqual(response.status_code, 200)
     try:
         xmlrpclib.loads(response.content)
         self.fail('parse error expected')
     except xmlrpclib.Fault, fault:
         self.assertEqual(fault.faultCode, 1)