Example #1
0
class JSONRPCTestValidateFormat(unittest.TestCase):
    def setUp(self):
        self.jsonrpc = SLOJSONRPC(sessionfaker())

    def test_no_jsonrpc(self):
        try:
            self.jsonrpc._validate_format({'method': 'do'})
        except SLOJSONRPCError as err:
            self.assertEqual(err.errorcode, -32600)
        else:
            self.fail('Expected Error')

    def test_no_method(self):
        try:
            self.jsonrpc._validate_format({'jsonrpc': '2.0'})
        except SLOJSONRPCError as err:
            self.assertEqual(err.errorcode, -32600)
        else:
            self.fail('Expected Error')

    def test_wrong_version(self):
        try:
            self.jsonrpc._validate_format({'jsonrpc': '2.1', 'method': 'do'})
        except SLOJSONRPCError as err:
            self.assertEqual(err.errorcode, -32600)
        else:
            self.fail('Expected Error')

    def test_invalid_key(self):
        try:
            self.jsonrpc._validate_format({'jsonrpc': '2.1',
                                           'method': 'do', 'fd': None})
        except SLOJSONRPCError as err:
            self.assertEqual(err.errorcode, -32600)
        else:
            self.fail('Expected Error')