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

def test_file_fields_stream(self):

    class StreamFile(Document, ):
        the_file = FileField()
    StreamFile.drop_collection()
    text = six.b('Hello,    World!')
    more_text = six.b('Foo    Bar')
    content_type = 'text/plain'
    streamfile = StreamFile()
    streamfile.the_file.new_file(content_type=content_type)
    streamfile.the_file.write(text)
    streamfile.the_file.write(more_text)
    streamfile.the_file.close()
    streamfile.save()
    result = StreamFile.objects.first()
    self.assertTrue((streamfile == result))
    self.assertEqual(result.the_file.read(), (text + more_text))
    self.assertEqual(result.the_file.content_type, content_type)
    result.the_file.seek(0)
    self.assertEqual(result.the_file.tell(), 0)
    self.assertEqual(result.the_file.read(len(text)), text)
    self.assertEqual(result.the_file.tell(), len(text))
    self.assertEqual(result.the_file.read(len(more_text)), more_text)
    self.assertEqual(result.the_file.tell(), len((text + more_text)))
    result.the_file.delete()
    self.assertTrue((result.the_file.read() is None))
