def test_invoice_shredder(event, order): InvoiceAddress.objects.create(company='Acme Company', street='221B Baker Street', zipcode='12345', city='London', country='UK', order=order) inv = generate_invoice(order) invoice_pdf_task.apply(args=(inv.pk,)) inv.refresh_from_db() assert inv.invoice_to == "Acme Company\n\n221B Baker Street\n12345 London" assert inv.file fname = inv.file.path assert os.path.exists(fname) s = InvoiceShredder(event) f = list(s.generate_files()) assert len(f) == 1 s.shred_data() inv.refresh_from_db() assert "Acme" not in inv.invoice_to assert "icket" not in inv.lines.first().description assert not inv.file assert not os.path.exists(fname)