コード例 #1
0
    def test_create_update(self):
        # create plain NyBlobFile
        bf = NyBlobFile()
        self.assertEqual(bf.content_type, 'application/octet-stream')
        self.assertEqual(bf.filename, None)
        self.assertEqual(bf.open().read(), '')

        # create NyBlobFile with properties and content
        bf2 = NyBlobFile(filename='my_file.txt', content_type='text/plain')
        f = bf2.open_write()
        f.write('hello world')
        f.close()
        self.assertEqual(bf2.content_type, 'text/plain')
        self.assertEqual(bf2.filename, 'my_file.txt')
        self.assertEqual(bf2.open().read(), 'hello world')

        # change properties and content
        f = bf2.open_write()
        f.write('other content')
        f.close()
        bf2.filename = 'other_file.txt'
        bf2.content_type = 'text/html'
        self.assertEqual(bf2.content_type, 'text/html')
        self.assertEqual(bf2.filename, 'other_file.txt')
        self.assertEqual(bf2.open().read(), 'other content')
コード例 #2
0
    def test_create_update(self):
        # create plain NyBlobFile
        bf = NyBlobFile()
        self.assertEqual(bf.content_type, 'application/octet-stream')
        self.assertEqual(bf.filename, None)
        self.assertEqual(bf.open().read(), '')

        # create NyBlobFile with properties and content
        bf2 = NyBlobFile(filename='my_file.txt', content_type='text/plain')
        f = bf2.open_write()
        f.write('hello world')
        f.close()
        self.assertEqual(bf2.content_type, 'text/plain')
        self.assertEqual(bf2.filename, 'my_file.txt')
        self.assertEqual(bf2.open().read(), 'hello world')

        # change properties and content
        f = bf2.open_write()
        f.write('other content')
        f.close()
        bf2.filename = 'other_file.txt'
        bf2.content_type = 'text/html'
        self.assertEqual(bf2.content_type, 'text/html')
        self.assertEqual(bf2.filename, 'other_file.txt')
        self.assertEqual(bf2.open().read(), 'other content')