def test_page_file_cleanup(): doc = create_doc('TestDocumentToDelete', '.pdf') # from celery tests page = Page.objects.create(numero=999, document=doc) page.save() f = File(open('documents/tests/files/testimage.jpg', 'rb')) page.bitmap_120.save('This120ShouldGetDeleted.jpg', f) page.bitmap_600.save('This600ShouldGetDeleted.jpg', f) page.bitmap_900.save('This900ShouldGetDeleted.jpg', f) bitmap_120 = page.bitmap_120.file.name bitmap_600 = page.bitmap_120.file.name bitmap_900 = page.bitmap_120.file.name page.delete() with pytest.raises(IOError) as errorinfo: file = open(bitmap_120, 'r') assert 'No such file or directory' in str(errorinfo) with pytest.raises(IOError) as errorinfo: file = open(bitmap_600, 'r') assert 'No such file or directory' in str(errorinfo) with pytest.raises(IOError) as errorinfo: file = open(bitmap_900, 'r') assert 'No such file or directory' in str(errorinfo)
def test_document_file_cleanup(): doc = create_doc('TestDocumentToDelete', '.pdf') # from celery tests doc.save() f = File(open('documents/tests/files/3pages.pdf', 'rb')) doc.pdf.save('ThisPdfShouldGetDeleted.pdf', f) doc.original.save("ThisOriginalShouldGetDeleted.pdf", f) # Get file paths originalfilename = doc.original.file.name pdffilename = doc.pdf.file.name doc.delete() with pytest.raises(IOError) as errorinfo: file = open(originalfilename, 'r') assert 'No such file or directory' in str(errorinfo) with pytest.raises(IOError) as errorinfo: file = open(pdffilename, 'r') assert 'No such file or directory' in str(errorinfo)
def test_document_file_cleanup(): doc = create_doc("TestDocumentToDelete", ".pdf") # from celery tests doc.save() with open("documents/tests/files/3pages.pdf", "rb") as fd: f = File(fd) doc.pdf.save("ThisPdfShouldGetDeleted.pdf", f) doc.original.save("ThisOriginalShouldGetDeleted.pdf", f) # Get file paths originalfilename = doc.original.file.name pdffilename = doc.pdf.file.name doc.delete() with pytest.raises(IOError) as errorinfo: open(originalfilename) assert "No such file or directory" in str(errorinfo) with pytest.raises(IOError) as errorinfo: open(pdffilename) assert "No such file or directory" in str(errorinfo)