MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / test_rest_request

Method test_rest_request

test/functional/interface_rest.py:49–73  ·  view source on GitHub ↗
(self, uri, http_method='GET', req_type=ReqType.JSON, body='', status=200, ret_type=RetType.JSON)

Source from the content-addressed store, hash-verified

47 self.skip_if_no_wallet()
48
49 def test_rest_request(self, uri, http_method='GET', req_type=ReqType.JSON, body='', status=200, ret_type=RetType.JSON):
50 rest_uri = '/rest' + uri
51 if req_type == ReqType.JSON:
52 rest_uri += '.json'
53 elif req_type == ReqType.BIN:
54 rest_uri += '.bin'
55 elif req_type == ReqType.HEX:
56 rest_uri += '.hex'
57
58 conn = http.client.HTTPConnection(self.url.hostname, self.url.port)
59 self.log.debug('%s %s %s', http_method, rest_uri, body)
60 if http_method == 'GET':
61 conn.request('GET', rest_uri)
62 elif http_method == 'POST':
63 conn.request('POST', rest_uri, body)
64 resp = conn.getresponse()
65
66 assert_equal(resp.status, status)
67
68 if ret_type == RetType.OBJ:
69 return resp
70 elif ret_type == RetType.BYTES:
71 return resp.read()
72 elif ret_type == RetType.JSON:
73 return json.loads(resp.read().decode('utf-8'), parse_float=Decimal)
74
75 def run_test(self):
76 self.url = urllib.parse.urlparse(self.nodes[0].url)

Callers 1

run_testMethod · 0.95

Calls 3

assert_equalFunction · 0.90
requestMethod · 0.80
readMethod · 0.45

Tested by

no test coverage detected