def execute(self): self._logger.info('execute() enter') try: result = self._unsafe_execute() str_result = logger_helper.bool_result_to_str(result) self._logger.info('execute() exit with result {0:s}'.format(str_result)) return result except Exception: self._logger.exception('exception in execute()') return False
def execute(self): result = False attempt_count = 0 self._logger.info("execute() enter") while attempt_count < self._max_attempt_count: self._logger.info("execute(): iteration number {0:d}".format(attempt_count + 1)) result = self._safe_execute() if result: break attempt_count += 1 str_result = logger_helper.bool_result_to_str(result) self._logger.info("execute() exit with result {0:s}".format(str_result)) return result
def send(self, data): self._logger.info('send(data) enter') conn = self._connection_factory() try: headers = {"Content-Type": "application/xml", "Accept": "text/plain"} conn.request('POST', self._path, data, headers) response = conn.getresponse() result = response.status == httplib.OK str_result = logger_helper.bool_result_to_str(result) self._logger.info('send(data) exit with result {0:s}'.format(str_result)) return result except BaseException: self._logger.exception('exception in send(data)') return False finally: conn.close()
def test_bool_value(self): self.assertEqual('successfully', logger_helper.bool_result_to_str(True)) self.assertEqual('fails', logger_helper.bool_result_to_str(False))
def test_other_value(self): self.assertEqual('successfully', logger_helper.bool_result_to_str(['Item'])) self.assertEqual('fails', logger_helper.bool_result_to_str([]))