def test_log(self, mock_ansiescapecodes): """Test whether the frame content is logged completely. """ mock_iframe_content = [ "Example of multi-line frame", "---------------------------" ] mock_iframe: IFrame = mock.Mock() mock_iframe.get_height.return_value = len(mock_iframe_content) mock_iframe.get_content.return_value = '\n'.join(mock_iframe_content) mock_iframe.get_position.return_value = 0 mock_ansiescapecodes.configure_mock(**self.__mock_ansiescapecodes_attr) captured_stdout = StringIO() with redirect_stdout(captured_stdout): logger: [ILogger, Thread] = Logger() logger.log(frame=mock_iframe) logger.end() frame_content = [ ''.join([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format( 300), self.__mock_ansiescapecodes_attr["CLEAR_LINE.value"], line, self.__mock_ansiescapecodes_attr["CURSOR_DOWN.value"].format(1) ]) for line in mock_iframe_content ] self.assertTrue(''.join(frame_content) in captured_stdout.getvalue())
def test_reset(self, mock_ansiescapecodes): """Test whether after a reset is not logged any frame. """ mock_iframe_content = [ "Example of multi-line frame", "---------------------------" ] mock_iframe: IFrame = mock.Mock() mock_iframe.get_height.return_value = len(mock_iframe_content) mock_iframe.get_content.return_value = '\n'.join(mock_iframe_content) mock_iframe.get_position.return_value = 0 mock_ansiescapecodes.configure_mock(**self.__mock_ansiescapecodes_attr) captured_stdout = StringIO() with redirect_stdout(captured_stdout): logger: [ILogger, Thread] = Logger() logger.log(frame=mock_iframe) # Sleep to leave time for the frame to be logged: sleep(0.1) logger.reset() sleep(0.1) logger.end() self.assertTrue(self.__mock_ansiescapecodes_attr["CLEAR_SCREEN.value"] in captured_stdout.getvalue()) after_clear_index = captured_stdout.getvalue().index( self.__mock_ansiescapecodes_attr["CLEAR_SCREEN.value"]) frame_content = [ ''.join([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format( 300), self.__mock_ansiescapecodes_attr["CLEAR_LINE.value"], line, self.__mock_ansiescapecodes_attr["CURSOR_DOWN.value"].format(1) ]) for line in mock_iframe_content ] frame_content.extend([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format(300), self.__mock_ansiescapecodes_attr["CURSOR_UP.value"].format(0) ]) self.assertTrue(''.join(frame_content) not in captured_stdout.getvalue()[after_clear_index:])
def test_log_not_end(self, mock_ansiescapecodes): """Test whether the cursor position is restored when logging. """ mock_iframe_content = [ "Example of multi-line frame", "---------------------------" ] mock_iframe: IFrame = mock.Mock() mock_iframe.get_height.return_value = len(mock_iframe_content) mock_iframe.get_content.return_value = '\n'.join(mock_iframe_content) mock_iframe.get_position.return_value = 0 mock_ansiescapecodes.configure_mock(**self.__mock_ansiescapecodes_attr) captured_stdout = StringIO() with redirect_stdout(captured_stdout): logger: [ILogger, Thread] = Logger() logger.log(frame=mock_iframe) # Sleep to leave time for the frame to be logged: sleep(0.1) with redirect_stdout(None): logger.end() frame_content = [ ''.join([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format( 300), self.__mock_ansiescapecodes_attr["CLEAR_LINE.value"], line, self.__mock_ansiescapecodes_attr["CURSOR_DOWN.value"].format(1) ]) for line in mock_iframe_content ] frame_content.extend([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format(300), self.__mock_ansiescapecodes_attr["CURSOR_UP.value"].format( len(mock_iframe_content)) ]) self.assertTrue(''.join(frame_content) in captured_stdout.getvalue()) frame_content[-1] = self.__mock_ansiescapecodes_attr[ "CURSOR_UP.value"].format(0) self.assertTrue( ''.join(frame_content) not in captured_stdout.getvalue())
metavar="max_row_length", type=max_row_length, help="limit selection to rows with this max length", default=DEFAULT_MAX_ROW_LENGTH, required=False) fetch_table.add_argument("-o", "--output_path", metavar="output_path", type=str, help="path to the output file", default="./blindpie.out", required=False) args = parser.parse_args() logger: ILogger = Logger() blindpie: IBlindpie = Blindpie(url=args.url, params=args.params, logger=logger) if args.command == "test": test_args = { "default_request": Request(params=args.params, method=args.method, headers=args.headers if args.headers is not None else DEFAULT_HEADERS), "params": list(args.params.keys()), "threshold": args.threshold,
def test_log_multiple_frames(self, mock_ansiescapecodes): """Test whether multiple frames are logged according to their index positions. """ mock_iframe_content_1 = [ "Example of multi-line frame 1", "---------------------------" ] mock_iframe_1: IFrame = mock.Mock() mock_iframe_1.get_height.return_value = len(mock_iframe_content_1) mock_iframe_1.get_content.return_value = '\n'.join( mock_iframe_content_1) mock_iframe_1.get_position.return_value = 0 mock_iframe_content_2 = [ "Example of multi-line frame 2", "---------------------------" ] mock_iframe_2: IFrame = mock.Mock() mock_iframe_2.get_height.return_value = len(mock_iframe_content_2) mock_iframe_2.get_content.return_value = '\n'.join( mock_iframe_content_2) mock_iframe_2.get_position.return_value = 1 mock_iframe_content_3 = ["Example of single-line frame 1"] mock_iframe_3: IFrame = mock.Mock() mock_iframe_3.get_height.return_value = len(mock_iframe_content_3) mock_iframe_3.get_content.return_value = '\n'.join( mock_iframe_content_3) mock_iframe_3.get_position.return_value = 2 mock_ansiescapecodes.configure_mock(**self.__mock_ansiescapecodes_attr) captured_stdout = StringIO() with redirect_stdout(captured_stdout): logger: [ILogger, Thread] = Logger() logger.log(frame=mock_iframe_1) logger.log(frame=mock_iframe_3) logger.log(frame=mock_iframe_2) logger.end() frames_contents = [ ''.join([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format( 300), self.__mock_ansiescapecodes_attr["CLEAR_LINE.value"], line, self.__mock_ansiescapecodes_attr["CURSOR_DOWN.value"].format(1) ]) for line in mock_iframe_content_1 ] frames_contents.extend([ ''.join([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format( 300), self.__mock_ansiescapecodes_attr["CLEAR_LINE.value"], line, self.__mock_ansiescapecodes_attr["CURSOR_DOWN.value"].format(1) ]) for line in mock_iframe_content_2 ]) frames_contents.extend([ ''.join([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format( 300), self.__mock_ansiescapecodes_attr["CLEAR_LINE.value"], line, self.__mock_ansiescapecodes_attr["CURSOR_DOWN.value"].format(1) ]) for line in mock_iframe_content_3 ]) frames_contents.extend([ self.__mock_ansiescapecodes_attr["CURSOR_LEFT.value"].format(300), self.__mock_ansiescapecodes_attr["CURSOR_UP.value"].format( len(mock_iframe_content_1) + len(mock_iframe_content_2) + len(mock_iframe_content_3)) ]) self.assertTrue(''.join(frames_contents) in captured_stdout.getvalue())