+ self.wfile.write(json.dumps(self._expected_responses["get"]).encode("utf-8"))
+ return self._expected_responses["get"]
+
+ def do_PUT(self):
+ request_body_json = self._get_request_body()
+ if request_body_json is not None:
+ self._apply_expected_data(request_body_json)
+ logging.info("EXPECTED RESPONSES: " + str(self._expected_responses))
+ logging.info("EXPECTED REQUESTS: " + str(self._expected_requests))
+ response_status = 200
+ else:
+ response_status = 400
+ self.send_response(response_status)
+ self._set_headers()
+
+ def _get_request_body(self):
+ content_len = int(self.headers['Content-Length'], 0)
+ parsed_req_body = None
+ if content_len > 0:
+ body = self.rfile.read(content_len)
+ body_decoded = body.decode('utf8')
+ logging.info("BODY: %s type: %s body decoded: %s type: %s", str(body), type(body), str(body_decoded),
+ type(body_decoded))
+ parsed_req_body = json.loads(body_decoded)
+ return parsed_req_body
+
+ def _apply_expected_data(self, request_body_json):
+ if self.path == '/setResponse':
+ logging.info("IN PUT /setResponse: " + str(request_body_json))
+ print("TYPE: %s and text: %s", type(request_body_json), str(request_body_json))
+ self._expected_responses.update(request_body_json)
+ print("TYPE: %s", type(request_body_json))
+ elif self.path == '/setRequest':
+ logging.info("IN PUT /setRequest: " + str(request_body_json))
+ self._expected_requests.update(request_body_json)