def test_notify(self): T = [[ (self._make_payload('jsonrpc.notify', ['this is a string'], version=v, is_notify=True), b('')), (self._make_payload('jsonrpc.notify', ['瓶喂的JSON-RPC'], version=v, is_notify=True), b('')), ] for v in ['2.0']] [[ self._assert_equals((self.app.post(self.service_url, data=req)).data, resp) for req, resp in t ] for t in T]
def test_batch_notify(self): req = json.dumps( [ {"jsonrpc": "2.0", "method": "jsonrpc.notify", "params": ["Flask"], "id": None}, {"jsonrpc": "2.0", "method": "jsonrpc.notify", "params": ["JSON-RPC"], "id": None}, ] ) resp = self.app.post(self.service_url, data=req).data self.assertEqual(b(""), resp)
def _extract_raw_data_request(request): if request.method == 'GET': return request.query_string elif request.method == 'POST': if request.data: return request.data elif request.form.to_dict(): return list(request.form.to_dict().keys())[0] return b('')
def test_payload_id_null(self): for version in ['1.0', '1.1', '2.0']: req = json.dumps({'jsonrpc': version, 'method': 'jsonrpc.echo'}) resp = self.app.post(self.service_url, data=req, headers={ 'Content-Type': 'application/json' }).data self.assertEqual(b(''), resp)
def _extract_raw_data_request(request): if request.method == 'GET': return request.query_string elif request.method == 'POST': if request.data: return request.data elif request.form.to_dict(): #return list(request.form.to_dict().keys())[0] return list(request.form.to_dict().keys())[0] if isinstance(list(request.form.to_dict().keys())[0], bytes) else list(request.form.to_dict().keys())[0].encode() return b('')
def test_batch_notify(self): req = json.dumps([ { 'jsonrpc': '2.0', 'method': 'jsonrpc.notify', 'params': ['Flask'], 'id': None }, { 'jsonrpc': '2.0', 'method': 'jsonrpc.notify', 'params': ['JSON-RPC'], 'id': None }, ]) resp = self.app.post(self.service_url, data=req).data self.assertEqual(b(''), resp)
def test_payload_id_none(self): req_id = None for version in ["1.0", "1.1", "2.0"]: req = json.dumps({"jsonrpc": version, "method": "jsonrpc.echo", "id": req_id}) resp = self.app.post(self.service_url, data=req, headers={"Content-Type": "application/json"}).data self.assertEqual(b(""), resp)
def test_notify(self): T = [ [ (self._make_payload("jsonrpc.notify", ["this is a string"], version=v, is_notify=True), b("")), (self._make_payload("jsonrpc.notify", ["瓶喂的JSON-RPC"], version=v, is_notify=True), b("")), ] for v in ["2.0"] ] [[self._assert_equals((self.app.post(self.service_url, data=req)).data, resp) for req, resp in t] for t in T]
def test_notify(self): T = [[ (self._make_payload('jsonrpc.notify', ['this is a string'], version=v, is_notify=True), b('')), ] for v in ['2.0']] [[self._assert_equals((self.app.post(self.service_url, data=req)).data, resp) for req, resp in t] for t in T]