def test_file_persistence(self): content = b'content1' with reversion.create_revision(): # add a file instance file1 = FileModel() file1.test_file.save('file1.txt', SimpleUploadedFile('file1.txt', content), False) file1.save() # manually add a revision because we use the explicit way # django-cms uses too. adapter = reversion.get_adapter(FileModel) if hasattr(reversion.models, 'VERSION_CHANGE'): reversion.revision_context_manager.add_to_context( reversion.default_revision_manager, file1, adapter.get_version_data(file1, VERSION_CHANGE)) else: reversion.revision_context_manager.add_to_context( reversion.default_revision_manager, file1, adapter.get_version_data(file1)) # reload the instance from db file2 = FileModel.objects.all()[0] # delete the instance. file2.delete() # revert the old version file_version = reversion.get_for_object(file1)[0] file_version.revert() # reload the reverted instance and check for its content file1 = FileModel.objects.all()[0] self.assertEqual(file1.test_file.file.read(), content)