File: test_bug29.py

package info (click to toggle)
python-jsonrpc 1.13.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 484 kB
  • sloc: python: 3,173; makefile: 155
file content (34 lines) | stat: -rw-r--r-- 857 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
""" Exmples of usage with tests.

Tests in this file represent examples taken from JSON-RPC specification.
http://www.jsonrpc.org/specification#examples

"""
import sys
import json

from ..manager import JSONRPCResponseManager

if sys.version_info < (2, 7):
    import unittest2 as unittest
else:
    import unittest


def isjsonequal(json1, json2):
    return json.loads(json1) == json.loads(json2)


class TestJSONRPCExamples(unittest.TestCase):
    def setUp(self):
        self.dispatcher = {
            "return_none": lambda: None,
        }

    def test_none_as_result(self):
        req = '{"jsonrpc": "2.0", "method": "return_none", "id": 0}'
        response = JSONRPCResponseManager.handle(req, self.dispatcher)
        self.assertTrue(isjsonequal(
            response.json,
            '{"jsonrpc": "2.0", "result": null, "id": 0}'
        ))