def test_errorVersion1(self): object = Fault("code", "message") result = dumps(object, version=VERSION_1) self.assertEquals( result, ('{"id": null, "result": null, "error": {"fault": "Fault", ' '"faultCode": "code", "faultString": "message"}}'))
def test_errorVersion2(self): object = Fault("code", "message") result = dumps(object, version=VERSION_2) self.assertEquals( result, ('{"jsonrpc": "2.0", "id": null, "error": {"message": "Fault", ' '"code": "code", "data": "message"}}'))
def test_errorVersionPre1(self): object = Fault("code", "message") result = dumps(object, version=VERSION_PRE1) self.assertEquals( result, ('{"fault": "Fault", "faultCode": "code", ' '"faultString": "message"}'))
def test_noVersionError(self): object = Fault("code", "message") result = dumps(object) self.assertEquals( result, ('{"fault": "Fault", "faultCode": "code", ' '"faultString": "message"}'))
def test_errorVersionPre1(self): expected = { "fault": "Fault", "faultCode": "code", "faultString": "message" } fault = Fault("code", "message") result = dumps(fault, version=VERSION_PRE1) json_result = json.loads(result) self.assertEquals(expected, json_result)
def test_noVersionError(self): expected = { "fault": "Fault", "faultCode": "code", "faultString": "message" } fault = Fault("code", "message") result = dumps(fault) json_result = json.loads(result) self.assertEquals(expected, json_result)
def test_FaultLoads(self): dl = [] for version in (VERSION_PRE1, VERSION_2, VERSION_1): object = Fault("code", "message") d = defer.maybeDeferred(loads, dumps(object, version=version)) d = self.assertFailure(d, Fault) def callback(exc): self.assertEquals(exc.faultCode, object.faultCode) self.assertEquals(exc.faultString, object.faultString) d.addCallback(callback) dl.append(d) return defer.DeferredList(dl, fireOnOneErrback=True)
def test_errorVersion2(self): expected = { 'jsonrpc': '2.0', 'id': None, 'error': { 'message': 'message', 'code': 'code', 'data': 'message' } } fault = Fault('code', 'message') result = dumps(fault, version=VERSION_2) json_result = json.loads(result) self.assertEquals(expected, json_result)