def test_send_html_report_ascii(): with patch('pybloqs.email.smtplib.SMTP') as mock_smtp_constructor, \ patch('pybloqs.email.user_config', user_config): bloq = pybloqs.VStack([pybloqs.Block(u"This should show euro '€'.")]) bloq.email(title='Test bloqs email: ascii', from_address='*****@*****.**', recipients=['*****@*****.**']) mock_smtp_constructor.return_value.sendmail.assert_called_once_with( '*****@*****.**', ['*****@*****.**'], ANY) msg = mock_smtp_constructor.return_value.sendmail.call_args[0][2] assert 'Subject: Test bloqs email: ascii' in msg assert 'From: [email protected]' in msg assert 'To: [email protected]' in msg assert 'Content-Type: text/html; charset="us-ascii"' in msg assert "This should show euro ''." in msg # this has stripped out the non ascii / utf8 char
def test_pdf_converter_output(converter_name): with patch('pybloqs.htmlconv.user_config', {'pdf_converter': converter_name}): # Test if header and footer are included twice (once per page) page_one = p.Block('Lorem', styles={"page-break-after": "always"}) page_two = p.Block('ipsum') body = p.VStack([page_one, page_two]) header_text = uuid.uuid4().hex header = p.Block(header_text) footer_text = uuid.uuid4().hex footer = p.Block(footer_text, styles={'background': 'red'}) pdf_file = body.save(fmt='pdf', header_block=header, header_spacing=50, footer_block=footer, footer_spacing=50) output = run_pdftotext(pdf_file) assert output.count(header_text) == 2 assert output.count(footer_text) == 2 output = run_pdfinfo(pdf_file) assert output['Pages'] == '2' page_width, _, page_height, _, label = output['Page size'].split(' ') # Rounding errors between different converters. Need to check approximate values. assert np.isclose(float(page_height), A4_LONG_PTS, atol=0.1) assert np.isclose(float(page_width), A4_SHORT_PTS, atol=0.1) assert label == '(A4)' # Variation: Check that landscape format works pdf_file = body.save(fmt='pdf', orientation=LANDSCAPE) output = run_pdfinfo(pdf_file) page_width, _, page_height, _, label = output['Page size'].split(' ') assert np.isclose(float(page_height), A4_SHORT_PTS, atol=0.1) assert np.isclose(float(page_width), A4_LONG_PTS, atol=0.1) assert label == '(A4)' # Variation: Check that page size works pdf_file = body.save(fmt='pdf', pdf_page_size='Legal') output = run_pdfinfo(pdf_file) # No rounding errors between converters for 'Legal' format assert output['Page size'] == '612 x 1008 pts'
def test_send_html_report_utf8(): with patch('pybloqs.email.smtplib.SMTP') as mock_smtp_constructor, \ patch('pybloqs.email.user_config', user_config): bloq = pybloqs.VStack([pybloqs.Block(u"This should show euro '€'.")]) bloq.email(title='Test bloqs email: utf-8', from_address='*****@*****.**', recipients=['*****@*****.**', '*****@*****.**'], cc=['*****@*****.**', '*****@*****.**'], bcc=['*****@*****.**', '*****@*****.**'], convert_to_ascii=False) mock_smtp_constructor.return_value.sendmail.assert_called_once_with( '*****@*****.**', [ '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**' ], ANY) msg = mock_smtp_constructor.return_value.sendmail.call_args[0][2] assert 'Subject: Test bloqs email: utf-8' in msg assert 'From: [email protected]' in msg assert 'To: [email protected],[email protected]' in msg assert 'Cc: [email protected],[email protected]' in msg assert '*****@*****.**' not in msg and '*****@*****.**' not in msg assert 'Content-Type: text/html; charset="utf-8"' in msg