'Ensure that file fields can be written to and their data retrieved'

def test_file_fields(self):

    class PutFile(Document, ):
        the_file = FileField()
    PutFile.drop_collection()
    text = six.b('Hello,    World!')
    content_type = 'text/plain'
    putfile = PutFile()
    putfile.the_file.put(text, content_type=content_type, filename='hello')
    putfile.save()
    result = PutFile.objects.first()
    self.assertTrue((putfile == result))
    self.assertEqual(('%s' % result.the_file), '<GridFSProxy:    hello>')
    self.assertEqual(result.the_file.read(), text)
    self.assertEqual(result.the_file.content_type, content_type)
    result.the_file.delete()
    PutFile.objects.delete()
    PutFile.drop_collection()
    putfile = PutFile()
    putstring = StringIO()
    putstring.write(text)
    putstring.seek(0)
    putfile.the_file.put(putstring, content_type=content_type)
    putfile.save()
    result = PutFile.objects.first()
    self.assertTrue((putfile == result))
    self.assertEqual(result.the_file.read(), text)
    self.assertEqual(result.the_file.content_type, content_type)
    result.the_file.delete()
