'Test disk space usage when we delete/replace a file'

def test_file_disk_space(self):

    class TestFile(Document, ):
        the_file = FileField()
    text = six.b('Hello,    World!')
    content_type = 'text/plain'
    testfile = TestFile()
    testfile.the_file.put(text, content_type=content_type, filename='hello')
    testfile.save()
    db = TestFile._get_db()
    files = db.fs.files.find()
    chunks = db.fs.chunks.find()
    self.assertEquals(len(list(files)), 1)
    self.assertEquals(len(list(chunks)), 1)
    testfile.delete()
    files = db.fs.files.find()
    chunks = db.fs.chunks.find()
    self.assertEquals(len(list(files)), 0)
    self.assertEquals(len(list(chunks)), 0)
    testfile = TestFile()
    testfile.save()
    files = db.fs.files.find()
    chunks = db.fs.chunks.find()
    self.assertEquals(len(list(files)), 0)
    self.assertEquals(len(list(chunks)), 0)
    testfile.delete()
    files = db.fs.files.find()
    chunks = db.fs.chunks.find()
    self.assertEquals(len(list(files)), 0)
    self.assertEquals(len(list(chunks)), 0)
    testfile = TestFile()
    testfile.the_file.put(text, content_type=content_type, filename='hello')
    testfile.save()
    text = six.b('Bonjour,    World!')
    testfile.the_file.replace(text, content_type=content_type, filename='hello')
    testfile.save()
    files = db.fs.files.find()
    chunks = db.fs.chunks.find()
    self.assertEquals(len(list(files)), 1)
    self.assertEquals(len(list(chunks)), 1)
    testfile.delete()
    files = db.fs.files.find()
    chunks = db.fs.chunks.find()
    self.assertEquals(len(list(files)), 0)
    self.assertEquals(len(list(chunks)), 0)
