| 116 | return 'http://127.0.0.1:' + str(self._port) |
| 117 | |
| 118 | def handle_request(self, request_handler: tornado.web.RequestHandler): |
| 119 | all_matches = [] |
| 120 | for mock_handler in self.mock_handlers: |
| 121 | all_matches.append((mock_handler, mock_handler.match(request_handler))) |
| 122 | |
| 123 | sorted_matches = sorted(all_matches, key=lambda x: (x[1].matches, x[1].match_count), reverse=True) |
| 124 | |
| 125 | (most_suitable_handler, match_result) = sorted_matches[0] |
| 126 | |
| 127 | if match_result.matches: |
| 128 | most_suitable_handler.handle(request_handler) |
| 129 | return |
| 130 | |
| 131 | raise Exception('Cannot match request + ' + repr(request_handler.request) + '\n' |
| 132 | + 'Most suitable handler : ' + most_suitable_handler.matcher_info() + '\n' |
| 133 | + 'Unmatches fields: ' + str(match_result.unmatched_fields)) |
| 134 | |
| 135 | def register_mock( |
| 136 | self, |