def test_get_first_five_rows_one_column(self): header = ['id'] raw_data = [ ['1'], ['2'], ] save_format, expected = first_five_rows_helper(header, raw_data) converted = convert_first_five_rows_to_list(header, save_format) self.assertEqual(converted, expected)
def test_get_first_five_rows_newline_various(self): header = ['id', 'name', 'etc'] raw_data = [ ['1', 'test_1', 'new\n\nat_end\n\n'], ['2', 'test_2', 'single\nat_end_too\n'], ] save_format, expected = first_five_rows_helper(header, raw_data) converted = convert_first_five_rows_to_list(header, save_format) self.assertEqual(converted, expected)
def test_get_first_five_rows_newline_middle(self): header = ['id', 'name', 'etc'] raw_data = [ ['1', 'test\nmiddle', 'new'], ['2', 'test_2', 'single'], ] save_format, expected = first_five_rows_helper(header, raw_data) converted = convert_first_five_rows_to_list(header, save_format) self.assertEqual(converted, expected)
def test_get_first_five_rows_one_column_with_crlf(self): header = ['id'] raw_data = [ ['1'], ['2\nshould_be_the_id'], ] save_format, expected = first_five_rows_helper(header, raw_data) converted = convert_first_five_rows_to_list(header, save_format) # This test fails on purpose becasue the format of the first five rows will not # support this use case. self.assertNotEqual(converted, expected)
def test_get_first_five_rows_newline_should_work(self): """ This test shows where this logic breaks down. There is no other way around this issue unless we move away from the |#*#| syntax and store it in a more supported CSV format syntax with quotes and escape characters :return: """ header = ['id', 'name', 'etc'] raw_data = [ ['1', 'test_1', 'new\n\nat_end\n\n'], ['2\nThisBreaksMe', 'test_2', 'single\nat_end_too\n'], ] save_format, expected = first_five_rows_helper(header, raw_data) converted = convert_first_five_rows_to_list(header, save_format) # This test passes as it is the expected behavior, even though it is wrong. # the ID of row 2 should be 2\nThisBreaksMe, but the convert_first_five_to_list does # not know that the crlf was part of the field and not the line break. self.assertNotEqual(converted, expected)