コード例 #1
0
    def test_call_out_must_not_freeze_first_line_if_report_has_no_header(self):
        with outputs.XLSXOutput() as output:
            for item in self.iterable_object:
                output.out(item)
            output.footer(['Total', 51])

        self.assertFalse(self.worksheet_mocked.freeze_panes.called)
コード例 #2
0
    def test_call_process_with_header_and_footer_must_call_write_with_correct_format(
            self):
        header_format = mock.MagicMock()
        footer_format = mock.MagicMock()

        self.workbook_mocked.add_format.side_effect = [
            header_format, footer_format
        ]

        with outputs.XLSXOutput() as output:
            output.header(['Name', 'Age'])
            for item in self.iterable_object:
                output.out(item)
            output.footer(['Total', 51])

        first_call, last_call = (
            self.worksheet_mocked.write_row.mock_calls[0],
            self.worksheet_mocked.write_row.mock_calls[-1],
        )

        # Header
        self.assertEqual(first_call,
                         mock.call(0, 0, ['Name', 'Age'], header_format))

        # Footer (1 of header and the content's length)
        footer_line = 1 + 2
        self.assertEqual(
            last_call, mock.call(footer_line, 0, ['Total', 51], footer_format))
コード例 #3
0
    def test_call_out_must_freeze_first_line_if_report_received_header(self):
        with outputs.XLSXOutput() as output:
            output.header(['Name', 'Age'])
            for item in self.iterable_object:
                output.out(item)
            output.footer(['Total', 51])

        self.worksheet_mocked.freeze_panes.assert_called_once_with(1, 0)
コード例 #4
0
    def test_call_out_must_set_column_with_minumum_if_row_value_is_very_small(
            self):
        rows = [
            ('Jo', 17),
            ('Ali', 45),
        ]

        with outputs.XLSXOutput() as output:
            for item in rows:
                output.out(item)

        columns_width = {
            0: outputs.XLSXOutput().min_width,
            1: outputs.XLSXOutput().min_width,
        }
        calls = [mock.call(i, i, v) for i, v in columns_width.items()]

        self.worksheet_mocked.set_column.assert_has_calls(calls)
コード例 #5
0
    def test_call_out_must_call_write_if_we_give_a_dict(self):
        with outputs.XLSXOutput() as output:
            output.out(OrderedDict([('name', 'Alisson'), ('age', 38)]))
            output.out(OrderedDict([('name', 'Joao'), ('age', 13)]))

        expected_calls = [
            mock.call(0, 0, ['Alisson', 38]),
            mock.call(1, 0, ['Joao', 13])
        ]

        self.assertEqual(self.worksheet_mocked.write_row.mock_calls,
                         expected_calls)
コード例 #6
0
    def test_call_out_must_call_write(self):
        with outputs.XLSXOutput() as output:
            output.out(['Alisson', 38])
            output.out(['Joao', 13])

        expected_calls = [
            mock.call(0, 0, ['Alisson', 38]),
            mock.call(1, 0, ['Joao', 13])
        ]

        self.assertEqual(self.worksheet_mocked.write_row.mock_calls,
                         expected_calls)
コード例 #7
0
    def test_call_out_must_call_add_format_to_header_and_footer(self):
        with outputs.XLSXOutput() as output:
            output.out(('Alisson', 38))

        calls = [
            mock.call({
                'bold': True,
                'bg_color': '#C9C9C9'
            }),  # header
            mock.call({
                'bold': True,
                'bg_color': '#DDDDDD'
            }),  # Footer
        ]

        self.assertEqual(self.workbook_mocked.add_format.mock_calls, calls)
コード例 #8
0
    def test_call_must_set_column_width_with_correct_chars_number(self):
        rows = [
            ('Joao', 'Testing large line', 'Small line'),
            ('Alisson dos Reis Perez', 'Test',
             'Width of the column must be max chars number'),
        ]

        with outputs.XLSXOutput() as output:
            for item in rows:
                output.out(item)

        columns_width = {
            0: len(rows[1][0]),
            1: len(rows[0][1]),
            2: len(rows[1][2]),
        }

        calls = [mock.call(i, i, v) for i, v in columns_width.items()]

        self.worksheet_mocked.set_column.assert_has_calls(calls)
コード例 #9
0
    def test_call_out_must_call_close(self):
        with outputs.XLSXOutput() as output:
            for item in self.iterable_object:
                output.out(item)

        self.assertTrue(self.workbook_mocked.close.called)
コード例 #10
0
    def test_call_out_must_call_workbook_add_worksheet(self):
        with outputs.XLSXOutput() as output:
            output.out(('Alisson', 38))

        self.assertTrue(self.workbook_mocked.add_worksheet.called)
コード例 #11
0
    def test_call_out_must_call_lib_constructor(self):
        with outputs.XLSXOutput() as output:
            output.out(('Alisson', 38))

        self.workbook_const_mocked.assert_called_once_with(output.filepath)