def test_generate_pdf_task(mock_http_response, mock_get_template, settings, tmpdir, monkeypatch): settings.MEDIA_ROOT = tmpdir.strpath invoice = InvoiceFactory.create() invoice.issue() assert invoice.pdf.dirty pisa_document_mock = MagicMock() monkeypatch.setattr('silver.models.documents.pdf.pisa.pisaDocument', pisa_document_mock) generate_pdf(invoice.id, invoice.kind) # pdf needs to be refreshed as the invoice reference in the test is not the same with the one # in the task invoice.pdf.refresh_from_db() assert not invoice.pdf.dirty assert invoice.pdf.url == settings.MEDIA_URL + invoice.get_pdf_upload_path( ) assert pisa_document_mock.call_count == 1 pisa_document_mock.assert_called_once_with( src=mock_get_template().render().encode('UTF-8'), dest=mock_http_response(), encoding='UTF-8', link_callback=fetch_resources)
def test_generate_pdf_task(settings, tmpdir, monkeypatch): settings.MEDIA_ROOT = tmpdir.strpath invoice = InvoiceFactory.create() invoice.issue() assert invoice.pdf.dirty pisa_document_mock = MagicMock(return_value=MagicMock(err=False)) monkeypatch.setattr('silver.models.documents.pdf.pisa.pisaDocument', pisa_document_mock) generate_pdf(invoice.id, invoice.kind) # pdf needs to be refreshed as the invoice reference in the test is not the same with the one # in the task invoice.pdf.refresh_from_db() assert not invoice.pdf.dirty assert invoice.pdf.url == settings.MEDIA_URL + invoice.get_pdf_upload_path( ) assert pisa_document_mock.call_count == 1 assert len(pisa_document_mock.mock_calls) == 1
def test_generate_pdf_task(settings, tmpdir, monkeypatch): settings.MEDIA_ROOT = tmpdir.strpath invoice = InvoiceFactory.create() invoice.issue() assert invoice.pdf.dirty generate_pdf_mock = MagicMock() monkeypatch.setattr( 'silver.models.documents.pdf.generate_pdf_template_object', generate_pdf_mock) generate_pdf(invoice.id, invoice.kind) # pdf needs to be refreshed as the invoice reference in the test is not the same with the one # in the task invoice.pdf.refresh_from_db() assert not invoice.pdf.dirty assert invoice.pdf.url == settings.MEDIA_URL + invoice.get_pdf_upload_path( ) assert generate_pdf_mock.call_count == 1
def test_generate_pdf_task(settings, tmpdir, monkeypatch): settings.MEDIA_ROOT = tmpdir.strpath invoice = InvoiceFactory.create() invoice.issue() assert invoice.pdf.dirty pisa_document_mock = MagicMock(return_value=MagicMock(err=False)) monkeypatch.setattr('silver.models.documents.pdf.pisa.pisaDocument', pisa_document_mock) generate_pdf(invoice.id, invoice.kind) # pdf needs to be refreshed as the invoice reference in the test is not the same with the one # in the task invoice.pdf.refresh_from_db() assert not invoice.pdf.dirty assert invoice.pdf.url == settings.MEDIA_URL + invoice.get_pdf_upload_path() assert pisa_document_mock.call_count == 1 assert len(pisa_document_mock.mock_calls) == 1