def handle_request(self): request = self.cherrypy.to_mapper_request() if Config.verbose: Log.info("Request data:") Log.normal(request) else: Log.request_url(self.cherrypy.url()) items = self.mapping_handler.mapping_item_for_mapping_request(request) if len(items) == 0: self.cherrypy.response.status = 500 Log.failed("No response found for request: {0}".format( self.cherrypy.url())) return "No response found for request" if len(items) > 1: Log.warn("Matched {0:d} items, choosing the first one".format( len(items))) if Config.verbose: Log.multiple_matches(items) matched_item = items[0] response = matched_item.response if Config.verbose: Log.log_request(matched_item.request, self.cherrypy.url()) delay = Config.delay if delay > 0: delay = delay / 1000 if Config.verbose: Log.info("Delay: {0:.3f}ms".format(delay)) sleep(delay) if response.body.body_type == BodyResponse.PYTHON: response.process_python_data({"request": request}) self.cherrypy.response.status = response.status self.fill_headers(response.headers) if Config.verbose: Log.log_response(response) return response.body_response()
def test_url(self): with patch("sys.stdout", new=StringIO()) as output: Log.request_url("http://localhost/pymocky") self.assertIn("Request with url: http://localhost/pymocky", output.getvalue().strip())