def test_get_base64_data_for_upload(self): # Test string test_str = 'This is a string for base64 conversion testing.' self.init_data['content'] = test_str exp_conv = Base64Converter.encode_string(test_str) att = AttachmentWrapper(**self.init_data) self.assert_equal(att.get_base64_data_for_upload(), exp_conv) # Test stream test_stream = StringIO('This is a stream for base64 conversion testing.') exp_conv = Base64Converter.encode_stream(test_stream) self.init_data['content'] = test_stream att = AttachmentWrapper(**self.init_data) self.assert_equal(att.get_base64_data_for_upload(), exp_conv) # Test file map file_map = dict(file1='test stream 1', file2='test stream 2') zip_stream = StringIO() archive = zipfile.ZipFile(zip_stream, 'a', zipfile.ZIP_DEFLATED, False) for fn, content in file_map.iteritems(): archive.writestr(fn, content) for zfile in archive.filelist: zfile.create_system = 0 archive.close() zip_stream.seek(0) exp_conv = Base64Converter.encode_zip_stream(zip_stream) self.init_data['content'] = file_map att = AttachmentWrapper(**self.init_data) self.assert_equal(att.get_base64_data_for_upload(), exp_conv) # Test error raising self.init_data['content'] = 1 att = AttachmentWrapper(**self.init_data) self.assert_raises(TypeError, att.get_base64_data_for_upload)
def test_get_base64_data_for_upload(self): # Test string test_str = 'This is a string for base64 conversion testing.' self.init_data['content'] = test_str exp_conv = Base64Converter.encode_string(test_str) att = AttachmentWrapper(**self.init_data) self.assert_equal(att.get_base64_data_for_upload(), exp_conv) # Test stream test_stream = StringIO( 'This is a stream for base64 conversion testing.') exp_conv = Base64Converter.encode_stream(test_stream) self.init_data['content'] = test_stream att = AttachmentWrapper(**self.init_data) self.assert_equal(att.get_base64_data_for_upload(), exp_conv) # Test file map file_map = dict(file1='test stream 1', file2='test stream 2') zip_stream = StringIO() archive = zipfile.ZipFile(zip_stream, 'a', zipfile.ZIP_DEFLATED, False) for fn, content in file_map.iteritems(): archive.writestr(fn, content) for zfile in archive.filelist: zfile.create_system = 0 archive.close() zip_stream.seek(0) exp_conv = Base64Converter.encode_zip_stream(zip_stream) self.init_data['content'] = file_map att = AttachmentWrapper(**self.init_data) self.assert_equal(att.get_base64_data_for_upload(), exp_conv) # Test error raising self.init_data['content'] = 1 att = AttachmentWrapper(**self.init_data) self.assert_raises(TypeError, att.get_base64_data_for_upload)
def test_decode_stream(self): test_stream = StringIO('This is a stream for base64 conversion testing.') conv = Base64Converter.encode_stream(test_stream) decoded_conv = Base64Converter.decode_to_stream(conv) decoded_cont = decoded_conv.read() test_stream.seek(0) exp_cont = test_stream.read() self.assert_equal(decoded_cont, exp_cont)
def test_decode_stream(self): test_stream = StringIO( 'This is a stream for base64 conversion testing.') conv = Base64Converter.encode_stream(test_stream) decoded_conv = Base64Converter.decode_to_stream(conv) decoded_cont = decoded_conv.read() test_stream.seek(0) exp_cont = test_stream.read() self.assert_equal(decoded_cont, exp_cont)
def test_encode_stream(self): test_stream = StringIO('This is a stream for base64 conversion testing.') exp_conv = Binary(test_stream.read()) self.assert_equal(Base64Converter.encode_stream(test_stream), exp_conv) test_stream.close()
def test_encode_stream(self): test_stream = StringIO( 'This is a stream for base64 conversion testing.') exp_conv = Binary(test_stream.read()) self.assert_equal(Base64Converter.encode_stream(test_stream), exp_conv) test_stream.close()