Beispiel #1
0
    def test_should_shorten_long_name_and_add_ellipsis(self, mock_canvas):

        it = iter(range(900, 300, -7))

        def stringWidth(text, *args):
            if text.startswith('PESEL'):
                return 134
            elif text.startswith('Ognivo'):
                return next(it)
            return 0

        mock_canvas.return_value.stringWidth.side_effect = stringWidth

        mock_debtor = mock.Mock()
        mock_debtor.name = 'lorem ipsum dolor sit amet ' * 5
        mock_debtor.identity.name = 'PESEL'
        mock_debtor.identity.value = '12345678901'

        FrontSide(Canvas(), mock.Mock()).render(mock_debtor, Chunk(1, 1, {}),
                                                0)

        mock_canvas.return_value.assert_has_calls([
            mock.call.beginText().textLine(
                'lorem ipsum dolor sit amet lorem ipsum dolor sit amet lore\u2026'
            )
        ],
                                                  any_order=True)
Beispiel #2
0
    def test_should_render_title(self, mock_canvas):

        mock_canvas.return_value.stringWidth.return_value = 120.0

        FrontSide(Canvas(), mock.Mock()).render(self.mock_debtor,
                                                Chunk(1, 1, {}), 0)

        mock_canvas.return_value.beginText.return_value.assert_has_calls([
            mock.call.setFont('FreeSansBold', 12.755905511811026,
                              15.30708661417323),
            mock.call.setTextRenderMode(0),
            mock.call.setCharSpace(0.0),
            mock.call.setWordSpace(0.0),
            mock.call.setRise(0.0),
            mock.call.textLine('Ognivo: '),
            mock.call.setFont('FreeSans', 12.755905511811026,
                              15.30708661417323),
            mock.call.setTextRenderMode(0),
            mock.call.setCharSpace(0.0),
            mock.call.setWordSpace(0.0),
            mock.call.setRise(0.0),
            mock.call.textLine('Jan Kowalski'),
            mock.call.setFont('FreeSans', 12.755905511811026,
                              15.30708661417323),
            mock.call.setTextRenderMode(0),
            mock.call.setCharSpace(0.0),
            mock.call.setWordSpace(0.0),
            mock.call.setRise(0.0),
            mock.call.getY(),
            mock.call.setTextOrigin(mock.ANY, mock.ANY),
            mock.call.textLine('PESEL # 12345678901')
        ])
Beispiel #3
0
    def test_should_render_table(self, mock_canvas):

        mock_canvas.return_value.stringWidth.return_value = 120

        FrontSide(Canvas(), mock.Mock()).render(self.mock_debtor,
                                                Chunk(1, 1, {}), 0)

        # body
        mock_canvas.return_value.assert_has_calls([
            mock.call.setLineCap(2),
            mock.call.setLineWidth(0.2834645669291339),
            mock.call.grid([
                49.60629921259835, 162.9921259842519, 233.85826771653538,
                318.89763779527556, 389.763779527559, 474.8031496062992,
                545.6692913385826
            ], [
                758.2677165354331, 727.0866141732284, 695.9055118110236,
                664.7244094488188, 633.5433070866142, 602.3622047244095,
                571.1811023622047, 540.0, 508.81889763779526,
                477.6377952755905, 446.4566929133858, 415.27559055118104,
                384.09448818897636, 352.9133858267716, 321.7322834645669,
                290.55118110236214, 259.37007874015745, 228.1889763779527,
                197.00787401574797, 165.82677165354323, 134.64566929133852,
                103.46456692913371, 72.28346456692898, 41.10236220472425
            ])
        ])

        # header
        mock_canvas.return_value.assert_has_calls([
            mock.call.setLineWidth(0.8503937007874016),
            mock.call.grid([
                49.60629921259835, 162.9921259842519, 233.85826771653538,
                318.89763779527556, 389.763779527559, 474.8031496062992,
                545.6692913385826
            ], [800.7874015748032, 758.2677165354331]),
        ])

        # column titles
        mock_canvas.return_value.beginText.return_value.textLine.assert_has_calls(
            [
                mock.call('Bank'),
                mock.call('Data'),
                mock.call('z\u0142o\u017cenia'),
                mock.call('zapytania'),
                mock.call('Podpis'),
                mock.call('sk\u0142adaj\u0105cego'),
                mock.call('zapytanie'),
                mock.call('Data'),
                mock.call('odbioru'),
                mock.call('odpowiedzi'),
                mock.call('Podpis'),
                mock.call('odbieraj\u0105cego'),
                mock.call('odpowied\u017a'),
                mock.call('Rodzaj'),
                mock.call('odpowiedzi')
            ])
Beispiel #4
0
    def test_should_add_page_if_document_has_previous_pages(
            self, mock_add_page):

        canvas = Canvas()
        canvas.add_page()

        FrontSide(canvas, mock.Mock()).render(self.mock_debtor,
                                              Chunk(1, 1, {}), 0)

        self.assertEqual(mock_add_page.call_count, 2)
Beispiel #5
0
    def test_should_call_chunk_asdict(self, mock_canvas):

        mock_canvas.return_value.stringWidth.return_value = -999.0

        mock_chunk = mock.Mock()
        mock_chunk.count = 2
        mock_chunk.num = 1
        mock_chunk.data = {}
        mock_chunk._asdict.return_value = {'count': 2, 'num': 1, 'data': {}}

        mock_debtor = mock.Mock()
        mock_debtor.name = 'Jan Kowalski'

        FrontSide(Canvas(), mock.Mock()).render(mock_debtor, mock_chunk, 0)
        mock_chunk._asdict.assert_called()
Beispiel #6
0
    def test_should_render_replies_sorted_by_name_of_bank(
            self, mock_table, mock_canvas):

        mock_canvas.return_value.stringWidth.return_value = 0.0

        bank1 = mock.Mock()
        bank1.code = '00123'
        bank1.prefix = '001'
        bank1.name = 'Lorem Bank'

        bank2 = mock.Mock()
        bank2.code = '30211'
        bank2.prefix = '302'
        bank2.name = 'Dolor Bank'

        reply1 = mock.Mock()
        reply1.date_string = '1970-01-01'
        reply1.time_string = None
        reply1.has_account = True

        reply2 = mock.Mock()
        reply2.date_string = '1980-01-01'
        reply2.time_string = None
        reply2.has_account = False

        replies = Chunk(1, 1, {
            bank1: reply1,
            bank2: reply2,
        })

        mock_table.return_value.width = 175
        mock_table.return_value.x = 0

        FrontSide(Canvas(), mock.Mock()).render(self.mock_debtor, replies, 0)

        mock_table.return_value.assert_has_calls([
            mock.call.cell(0, 0, 'Dolor Bank'),
            mock.call.cell(0, 0, '302', HAlign.RIGHT, VAlign.BOTTOM),
            mock.call.cell(3, 0, '1980-01-01', HAlign.CENTER, VAlign.MIDDLE),
            mock.call.cell(5, 0, 'NIE', HAlign.CENTER, VAlign.MIDDLE),
            mock.call.cell(0, 1, 'Lorem Bank'),
            mock.call.cell(0, 1, '001', HAlign.RIGHT, VAlign.BOTTOM),
            mock.call.cell(3, 1, '1970-01-01', HAlign.CENTER, VAlign.MIDDLE),
            mock.call.cell(5, 1, 'TAK', HAlign.CENTER, VAlign.MIDDLE)
        ])
Beispiel #7
0
 def test_should_show_time(self, mock_config):
     mock_config.return_value.get = mock.Mock(return_value='tRUe')
     front_side = FrontSide(mock.Mock(), mock.Mock())
     self.assertTrue(front_side._should_show_time())
Beispiel #8
0
 def test_should_not_show_time_explicit(self, mock_config):
     mock_config.return_value.get = mock.Mock(return_value='fAlSe')
     front_side = FrontSide(mock.Mock(), mock.Mock())
     self.assertFalse(front_side._should_show_time())
Beispiel #9
0
 def test_should_not_show_time_by_default(self, mock_config):
     mock_config.return_value.get = mock.Mock(return_value=None)
     front_side = FrontSide(mock.Mock(), mock.Mock())
     self.assertFalse(front_side._should_show_time())
Beispiel #10
0
 def test_should_render_footer_on_front_side(self, mock_canvas):
     mock_canvas.return_value.stringWidth.return_value = 0.0
     FrontSide(Canvas(), mock.Mock()).render(self.mock_debtor,
                                             Chunk(1, 1, {}), 555)
     mock_canvas.return_value.beginText.return_value.assert_has_calls(
         [mock.call.textLine('Strona 555')])
Beispiel #11
0
 def test_should_render_watermark(self):
     mock_watermark = mock.Mock()
     FrontSide(Canvas(), mock_watermark).render(self.mock_debtor,
                                                Chunk(1, 1, {}), 0)
     mock_watermark.render.assert_called_once_with(mock.ANY)
Beispiel #12
0
 def test_should_add_page_if_document_has_no_previous_pages(
         self, mock_add_page):
     FrontSide(Canvas(), mock.Mock()).render(self.mock_debtor,
                                             Chunk(1, 1, {}), 0)
     mock_add_page.assert_called_once_with()
Beispiel #13
0
 def test_should_compute_number_of_rows(self):
     self.assertEqual(23, FrontSide(Canvas(), mock.Mock()).num_rows)