def test_custom_encoder(self): eq = self.assertEqual def encoder(msg): orig = msg.get_payload() msg.set_payload(0) msg['Content-Transfer-Encoding'] = 'broken64' au = MIMEAudio(self._audiodata, _encoder=encoder) eq(au.get_payload(), 0) eq(au['content-transfer-encoding'], 'broken64')
class TestMIMEAudio(unittest.TestCase): def setUp(self): # In Python, audiotest.au lives in Lib/test not Lib/test/data fp = open(findfile('audiotest.au')) try: self._audiodata = fp.read() finally: fp.close() self._au = MIMEAudio(self._audiodata) def test_guess_minor_type(self): self.assertEqual(self._au.get_type(), 'audio/basic') def test_encoding(self): payload = self._au.get_payload() self.assertEqual(base64.decodestring(payload), self._audiodata) def checkSetMinor(self): au = MIMEAudio(self._audiodata, 'fish') self.assertEqual(im.get_type(), 'audio/fish') def test_custom_encoder(self): eq = self.assertEqual def encoder(msg): orig = msg.get_payload() msg.set_payload(0) msg['Content-Transfer-Encoding'] = 'broken64' au = MIMEAudio(self._audiodata, _encoder=encoder) eq(au.get_payload(), 0) eq(au['content-transfer-encoding'], 'broken64') def test_add_header(self): eq = self.assertEqual unless = self.failUnless self._au.add_header('Content-Disposition', 'attachment', filename='audiotest.au') eq(self._au['content-disposition'], 'attachment; filename="audiotest.au"') eq(self._au.get_params(header='content-disposition'), [('attachment', ''), ('filename', 'audiotest.au')]) eq(self._au.get_param('filename', header='content-disposition'), 'audiotest.au') missing = [] eq(self._au.get_param('attachment', header='content-disposition'), '') unless( self._au.get_param('foo', failobj=missing, header='content-disposition') is missing) # Try some missing stuff unless(self._au.get_param('foobar', missing) is missing) unless( self._au.get_param('attachment', missing, header='foobar') is missing)
def test_custom_encoder(self): eq = self.assertEqual def encoder(msg): orig = msg.get_payload() msg.set_payload(0) msg['Content-Transfer-Encoding'] = 'broken64' au = MIMEAudio(self._audiodata, _encoder=encoder) eq(au.get_payload(), 0) eq(au['content-transfer-encoding'], 'broken64')
class TestMIMEAudio(unittest.TestCase): def setUp(self): # In Python, audiotest.au lives in Lib/test not Lib/test/data fp = open(findfile('audiotest.au')) try: self._audiodata = fp.read() finally: fp.close() self._au = MIMEAudio(self._audiodata) def test_guess_minor_type(self): self.assertEqual(self._au.get_type(), 'audio/basic') def test_encoding(self): payload = self._au.get_payload() self.assertEqual(base64.decodestring(payload), self._audiodata) def checkSetMinor(self): au = MIMEAudio(self._audiodata, 'fish') self.assertEqual(im.get_type(), 'audio/fish') def test_custom_encoder(self): eq = self.assertEqual def encoder(msg): orig = msg.get_payload() msg.set_payload(0) msg['Content-Transfer-Encoding'] = 'broken64' au = MIMEAudio(self._audiodata, _encoder=encoder) eq(au.get_payload(), 0) eq(au['content-transfer-encoding'], 'broken64') def test_add_header(self): eq = self.assertEqual unless = self.failUnless self._au.add_header('Content-Disposition', 'attachment', filename='audiotest.au') eq(self._au['content-disposition'], 'attachment; filename="audiotest.au"') eq(self._au.get_params(header='content-disposition'), [('attachment', ''), ('filename', 'audiotest.au')]) eq(self._au.get_param('filename', header='content-disposition'), 'audiotest.au') missing = [] eq(self._au.get_param('attachment', header='content-disposition'), '') unless(self._au.get_param('foo', failobj=missing, header='content-disposition') is missing) # Try some missing stuff unless(self._au.get_param('foobar', missing) is missing) unless(self._au.get_param('attachment', missing, header='foobar') is missing)
# Copyright (C) 2001 Python Software Foundation