(self, uri, http_method='GET', req_type=ReqType.JSON, body='', status=200, ret_type=RetType.JSON)
| 58 | self.supports_cli = False |
| 59 | |
| 60 | def test_rest_request(self, uri, http_method='GET', req_type=ReqType.JSON, body='', status=200, ret_type=RetType.JSON): |
| 61 | rest_uri = '/rest' + uri |
| 62 | if req_type == ReqType.JSON: |
| 63 | rest_uri += '.json' |
| 64 | elif req_type == ReqType.BIN: |
| 65 | rest_uri += '.bin' |
| 66 | elif req_type == ReqType.HEX: |
| 67 | rest_uri += '.hex' |
| 68 | |
| 69 | conn = http.client.HTTPConnection(self.url.hostname, self.url.port) |
| 70 | self.log.debug(f'{http_method} {rest_uri} {body}') |
| 71 | if http_method == 'GET': |
| 72 | conn.request('GET', rest_uri) |
| 73 | elif http_method == 'POST': |
| 74 | conn.request('POST', rest_uri, body) |
| 75 | resp = conn.getresponse() |
| 76 | |
| 77 | assert_equal(resp.status, status) |
| 78 | |
| 79 | if ret_type == RetType.OBJ: |
| 80 | return resp |
| 81 | elif ret_type == RetType.BYTES: |
| 82 | return resp.read() |
| 83 | elif ret_type == RetType.JSON: |
| 84 | return json.loads(resp.read().decode('utf-8'), parse_float=Decimal) |
| 85 | |
| 86 | def run_test(self): |
| 87 | self.url = urllib.parse.urlparse(self.nodes[0].url) |
no test coverage detected