Back to index

python3.2  3.2.2
Public Member Functions | Private Attributes
email.test.test_email.TestMultipart Class Reference
Inheritance diagram for email.test.test_email.TestMultipart:
Inheritance graph
[legend]
Collaboration diagram for email.test.test_email.TestMultipart:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def setUp
def test_hierarchy
def test_empty_multipart_idempotent
def test_no_parts_in_a_multipart_with_none_epilogue
def test_no_parts_in_a_multipart_with_empty_epilogue
def test_one_part_in_a_multipart
def test_seq_parts_in_a_multipart_with_empty_preamble
def test_seq_parts_in_a_multipart_with_none_preamble
def test_seq_parts_in_a_multipart_with_none_epilogue
def test_seq_parts_in_a_multipart_with_empty_epilogue
def test_seq_parts_in_a_multipart_with_nl_epilogue
def test_message_external_body
def test_double_boundary
def test_nested_inner_contains_outer_boundary
def test_nested_with_same_boundary
def test_boundary_in_non_multipart
def test_boundary_with_leading_space
def test_boundary_without_trailing_newline
def ndiffAssertEqual

Private Attributes

 _msg
 _im
 _txt

Detailed Description

Definition at line 1425 of file test_email.py.


Member Function Documentation

def email.test.test_email.TestEmailBase.ndiffAssertEqual (   self,
  first,
  second 
) [inherited]
Like assertEqual except use ndiff for readable output.

Definition at line 57 of file test_email.py.

00057 
00058     def ndiffAssertEqual(self, first, second):
00059         """Like assertEqual except use ndiff for readable output."""
00060         if first != second:
00061             sfirst = str(first)
00062             ssecond = str(second)
00063             rfirst = [repr(line) for line in sfirst.splitlines()]
00064             rsecond = [repr(line) for line in ssecond.splitlines()]
00065             diff = difflib.ndiff(rfirst, rsecond)
00066             raise self.failureException(NL + NL.join(diff))

Here is the call graph for this function:

Definition at line 1426 of file test_email.py.

01426 
01427     def setUp(self):
01428         with openfile('PyBanner048.gif', 'rb') as fp:
01429             data = fp.read()
01430         container = MIMEBase('multipart', 'mixed', boundary='BOUNDARY')
01431         image = MIMEImage(data, name='dingusfish.gif')
01432         image.add_header('content-disposition', 'attachment',
01433                          filename='dingusfish.gif')
01434         intro = MIMEText('''\
01435 Hi there,
01436 
01437 This is the dingus fish.
01438 ''')
01439         container.attach(intro)
01440         container.attach(image)
01441         container['From'] = 'Barry <barry@digicool.com>'
01442         container['To'] = 'Dingus Lovers <cravindogs@cravindogs.com>'
01443         container['Subject'] = 'Here is your dingus fish'
01444 
01445         now = 987809702.54848599
01446         timetuple = time.localtime(now)
01447         if timetuple[-1] == 0:
01448             tzsecs = time.timezone
01449         else:
01450             tzsecs = time.altzone
01451         if tzsecs > 0:
01452             sign = '-'
01453         else:
01454             sign = '+'
01455         tzoffset = ' %s%04d' % (sign, tzsecs / 36)
01456         container['Date'] = time.strftime(
01457             '%a, %d %b %Y %H:%M:%S',
01458             time.localtime(now)) + tzoffset
01459         self._msg = container
01460         self._im = image
01461         self._txt = intro

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1749 of file test_email.py.

01749 
01750     def test_boundary_in_non_multipart(self):
01751         msg = self._msgobj('msg_40.txt')
01752         self.assertEqual(msg.as_string(), '''\
01753 MIME-Version: 1.0
01754 Content-Type: text/html; boundary="--961284236552522269"
01755 
01756 ----961284236552522269
01757 Content-Type: text/html;
01758 Content-Transfer-Encoding: 7Bit
01759 
01760 <html></html>
01761 
01762 ----961284236552522269--
01763 ''')

Here is the call graph for this function:

Definition at line 1764 of file test_email.py.

01764 
01765     def test_boundary_with_leading_space(self):
01766         eq = self.assertEqual
01767         msg = email.message_from_string('''\
01768 MIME-Version: 1.0
01769 Content-Type: multipart/mixed; boundary="    XXXX"
01770 
01771 --    XXXX
01772 Content-Type: text/plain
01773 
01774 
01775 --    XXXX
01776 Content-Type: text/plain
01777 
01778 --    XXXX--
01779 ''')
01780         self.assertTrue(msg.is_multipart())
01781         eq(msg.get_boundary(), '    XXXX')
01782         eq(len(msg.get_payload()), 2)

Here is the call graph for this function:

Definition at line 1783 of file test_email.py.

01783 
01784     def test_boundary_without_trailing_newline(self):
01785         m = Parser().parsestr("""\
01786 Content-Type: multipart/mixed; boundary="===============0012394164=="
01787 MIME-Version: 1.0
01788 
01789 --===============0012394164==
01790 Content-Type: image/file1.jpg
01791 MIME-Version: 1.0
01792 Content-Transfer-Encoding: base64
01793 
01794 YXNkZg==
01795 --===============0012394164==--""")
01796         self.assertEqual(m.get_payload(0).get_payload(), 'YXNkZg==')
01797 
01798 
01799 
# Test some badly formatted messages

Here is the call graph for this function:

Definition at line 1706 of file test_email.py.

01706 
01707     def test_double_boundary(self):
01708         # msg_37.txt is a multipart that contains two dash-boundary's in a
01709         # row.  Our interpretation of RFC 2046 calls for ignoring the second
01710         # and subsequent boundaries.
01711         msg = self._msgobj('msg_37.txt')
01712         self.assertEqual(len(msg.get_payload()), 3)

Here is the call graph for this function:

Definition at line 1481 of file test_email.py.

01481 
01482     def test_empty_multipart_idempotent(self):
01483         text = """\
01484 Content-Type: multipart/mixed; boundary="BOUNDARY"
01485 MIME-Version: 1.0
01486 Subject: A subject
01487 To: aperson@dom.ain
01488 From: bperson@dom.ain
01489 
01490 
01491 --BOUNDARY
01492 
01493 
01494 --BOUNDARY--
01495 """
01496         msg = Parser().parsestr(text)
01497         self.ndiffAssertEqual(text, msg.as_string())

Here is the call graph for this function:

Definition at line 1462 of file test_email.py.

01462 
01463     def test_hierarchy(self):
01464         # convenience
01465         eq = self.assertEqual
01466         unless = self.assertTrue
01467         raises = self.assertRaises
01468         # tests
01469         m = self._msg
01470         unless(m.is_multipart())
01471         eq(m.get_content_type(), 'multipart/mixed')
01472         eq(len(m.get_payload()), 2)
01473         raises(IndexError, m.get_payload, 2)
01474         m0 = m.get_payload(0)
01475         m1 = m.get_payload(1)
01476         unless(m0 is self._txt)
01477         unless(m1 is self._im)
01478         eq(m.get_payload(), [m0, m1])
01479         unless(not m0.is_multipart())
01480         unless(not m1.is_multipart())

Here is the call graph for this function:

Definition at line 1693 of file test_email.py.

01693 
01694     def test_message_external_body(self):
01695         eq = self.assertEqual
01696         msg = self._msgobj('msg_36.txt')
01697         eq(len(msg.get_payload()), 2)
01698         msg1 = msg.get_payload(1)
01699         eq(msg1.get_content_type(), 'multipart/alternative')
01700         eq(len(msg1.get_payload()), 2)
01701         for subpart in msg1.get_payload():
01702             eq(subpart.get_content_type(), 'message/external-body')
01703             eq(len(subpart.get_payload()), 1)
01704             subsubpart = subpart.get_payload(0)
01705             eq(subsubpart.get_content_type(), 'text/plain')

Here is the call graph for this function:

Definition at line 1713 of file test_email.py.

01713 
01714     def test_nested_inner_contains_outer_boundary(self):
01715         eq = self.ndiffAssertEqual
01716         # msg_38.txt has an inner part that contains outer boundaries.  My
01717         # interpretation of RFC 2046 (based on sections 5.1 and 5.1.2) say
01718         # these are illegal and should be interpreted as unterminated inner
01719         # parts.
01720         msg = self._msgobj('msg_38.txt')
01721         sfp = StringIO()
01722         iterators._structure(msg, sfp)
01723         eq(sfp.getvalue(), """\
01724 multipart/mixed
01725     multipart/mixed
01726         multipart/alternative
01727             text/plain
01728         text/plain
01729     text/plain
01730     text/plain
01731 """)

Here is the call graph for this function:

Definition at line 1732 of file test_email.py.

01732 
01733     def test_nested_with_same_boundary(self):
01734         eq = self.ndiffAssertEqual
01735         # msg 39.txt is similarly evil in that it's got inner parts that use
01736         # the same boundary as outer parts.  Again, I believe the way this is
01737         # parsed is closest to the spirit of RFC 2046
01738         msg = self._msgobj('msg_39.txt')
01739         sfp = StringIO()
01740         iterators._structure(msg, sfp)
01741         eq(sfp.getvalue(), """\
01742 multipart/mixed
01743     multipart/mixed
01744         multipart/alternative
01745         application/octet-stream
01746         application/octet-stream
01747     text/plain
01748 """)

Here is the call graph for this function:

Definition at line 1515 of file test_email.py.

01515 
01516     def test_no_parts_in_a_multipart_with_empty_epilogue(self):
01517         outer = MIMEBase('multipart', 'mixed')
01518         outer['Subject'] = 'A subject'
01519         outer['To'] = 'aperson@dom.ain'
01520         outer['From'] = 'bperson@dom.ain'
01521         outer.preamble = ''
01522         outer.epilogue = ''
01523         outer.set_boundary('BOUNDARY')
01524         self.ndiffAssertEqual(outer.as_string(), '''\
01525 Content-Type: multipart/mixed; boundary="BOUNDARY"
01526 MIME-Version: 1.0
01527 Subject: A subject
01528 To: aperson@dom.ain
01529 From: bperson@dom.ain
01530 
01531 
01532 --BOUNDARY
01533 
01534 --BOUNDARY--
01535 ''')

Here is the call graph for this function:

Definition at line 1498 of file test_email.py.

01498 
01499     def test_no_parts_in_a_multipart_with_none_epilogue(self):
01500         outer = MIMEBase('multipart', 'mixed')
01501         outer['Subject'] = 'A subject'
01502         outer['To'] = 'aperson@dom.ain'
01503         outer['From'] = 'bperson@dom.ain'
01504         outer.set_boundary('BOUNDARY')
01505         self.ndiffAssertEqual(outer.as_string(), '''\
01506 Content-Type: multipart/mixed; boundary="BOUNDARY"
01507 MIME-Version: 1.0
01508 Subject: A subject
01509 To: aperson@dom.ain
01510 From: bperson@dom.ain
01511 
01512 --BOUNDARY
01513 
01514 --BOUNDARY--''')

Here is the call graph for this function:

Definition at line 1536 of file test_email.py.

01536 
01537     def test_one_part_in_a_multipart(self):
01538         eq = self.ndiffAssertEqual
01539         outer = MIMEBase('multipart', 'mixed')
01540         outer['Subject'] = 'A subject'
01541         outer['To'] = 'aperson@dom.ain'
01542         outer['From'] = 'bperson@dom.ain'
01543         outer.set_boundary('BOUNDARY')
01544         msg = MIMEText('hello world')
01545         outer.attach(msg)
01546         eq(outer.as_string(), '''\
01547 Content-Type: multipart/mixed; boundary="BOUNDARY"
01548 MIME-Version: 1.0
01549 Subject: A subject
01550 To: aperson@dom.ain
01551 From: bperson@dom.ain
01552 
01553 --BOUNDARY
01554 Content-Type: text/plain; charset="us-ascii"
01555 MIME-Version: 1.0
01556 Content-Transfer-Encoding: 7bit
01557 
01558 hello world
01559 --BOUNDARY--''')

Here is the call graph for this function:

Definition at line 1639 of file test_email.py.

01639 
01640     def test_seq_parts_in_a_multipart_with_empty_epilogue(self):
01641         eq = self.ndiffAssertEqual
01642         outer = MIMEBase('multipart', 'mixed')
01643         outer['Subject'] = 'A subject'
01644         outer['To'] = 'aperson@dom.ain'
01645         outer['From'] = 'bperson@dom.ain'
01646         outer.epilogue = ''
01647         msg = MIMEText('hello world')
01648         outer.attach(msg)
01649         outer.set_boundary('BOUNDARY')
01650         eq(outer.as_string(), '''\
01651 Content-Type: multipart/mixed; boundary="BOUNDARY"
01652 MIME-Version: 1.0
01653 Subject: A subject
01654 To: aperson@dom.ain
01655 From: bperson@dom.ain
01656 
01657 --BOUNDARY
01658 Content-Type: text/plain; charset="us-ascii"
01659 MIME-Version: 1.0
01660 Content-Transfer-Encoding: 7bit
01661 
01662 hello world
01663 --BOUNDARY--
01664 ''')
01665 

Here is the call graph for this function:

Definition at line 1560 of file test_email.py.

01560 
01561     def test_seq_parts_in_a_multipart_with_empty_preamble(self):
01562         eq = self.ndiffAssertEqual
01563         outer = MIMEBase('multipart', 'mixed')
01564         outer['Subject'] = 'A subject'
01565         outer['To'] = 'aperson@dom.ain'
01566         outer['From'] = 'bperson@dom.ain'
01567         outer.preamble = ''
01568         msg = MIMEText('hello world')
01569         outer.attach(msg)
01570         outer.set_boundary('BOUNDARY')
01571         eq(outer.as_string(), '''\
01572 Content-Type: multipart/mixed; boundary="BOUNDARY"
01573 MIME-Version: 1.0
01574 Subject: A subject
01575 To: aperson@dom.ain
01576 From: bperson@dom.ain
01577 
01578 
01579 --BOUNDARY
01580 Content-Type: text/plain; charset="us-ascii"
01581 MIME-Version: 1.0
01582 Content-Transfer-Encoding: 7bit
01583 
01584 hello world
01585 --BOUNDARY--''')
01586 

Here is the call graph for this function:

Definition at line 1666 of file test_email.py.

01666 
01667     def test_seq_parts_in_a_multipart_with_nl_epilogue(self):
01668         eq = self.ndiffAssertEqual
01669         outer = MIMEBase('multipart', 'mixed')
01670         outer['Subject'] = 'A subject'
01671         outer['To'] = 'aperson@dom.ain'
01672         outer['From'] = 'bperson@dom.ain'
01673         outer.epilogue = '\n'
01674         msg = MIMEText('hello world')
01675         outer.attach(msg)
01676         outer.set_boundary('BOUNDARY')
01677         eq(outer.as_string(), '''\
01678 Content-Type: multipart/mixed; boundary="BOUNDARY"
01679 MIME-Version: 1.0
01680 Subject: A subject
01681 To: aperson@dom.ain
01682 From: bperson@dom.ain
01683 
01684 --BOUNDARY
01685 Content-Type: text/plain; charset="us-ascii"
01686 MIME-Version: 1.0
01687 Content-Transfer-Encoding: 7bit
01688 
01689 hello world
01690 --BOUNDARY--
01691 
01692 ''')

Here is the call graph for this function:

Definition at line 1613 of file test_email.py.

01613 
01614     def test_seq_parts_in_a_multipart_with_none_epilogue(self):
01615         eq = self.ndiffAssertEqual
01616         outer = MIMEBase('multipart', 'mixed')
01617         outer['Subject'] = 'A subject'
01618         outer['To'] = 'aperson@dom.ain'
01619         outer['From'] = 'bperson@dom.ain'
01620         outer.epilogue = None
01621         msg = MIMEText('hello world')
01622         outer.attach(msg)
01623         outer.set_boundary('BOUNDARY')
01624         eq(outer.as_string(), '''\
01625 Content-Type: multipart/mixed; boundary="BOUNDARY"
01626 MIME-Version: 1.0
01627 Subject: A subject
01628 To: aperson@dom.ain
01629 From: bperson@dom.ain
01630 
01631 --BOUNDARY
01632 Content-Type: text/plain; charset="us-ascii"
01633 MIME-Version: 1.0
01634 Content-Transfer-Encoding: 7bit
01635 
01636 hello world
01637 --BOUNDARY--''')
01638 

Here is the call graph for this function:

Definition at line 1587 of file test_email.py.

01587 
01588     def test_seq_parts_in_a_multipart_with_none_preamble(self):
01589         eq = self.ndiffAssertEqual
01590         outer = MIMEBase('multipart', 'mixed')
01591         outer['Subject'] = 'A subject'
01592         outer['To'] = 'aperson@dom.ain'
01593         outer['From'] = 'bperson@dom.ain'
01594         outer.preamble = None
01595         msg = MIMEText('hello world')
01596         outer.attach(msg)
01597         outer.set_boundary('BOUNDARY')
01598         eq(outer.as_string(), '''\
01599 Content-Type: multipart/mixed; boundary="BOUNDARY"
01600 MIME-Version: 1.0
01601 Subject: A subject
01602 To: aperson@dom.ain
01603 From: bperson@dom.ain
01604 
01605 --BOUNDARY
01606 Content-Type: text/plain; charset="us-ascii"
01607 MIME-Version: 1.0
01608 Content-Transfer-Encoding: 7bit
01609 
01610 hello world
01611 --BOUNDARY--''')
01612 

Here is the call graph for this function:


Member Data Documentation

Definition at line 1459 of file test_email.py.

Definition at line 1458 of file test_email.py.

Definition at line 1460 of file test_email.py.


The documentation for this class was generated from the following file: