MCPcopy Index your code
hub / github.com/python/cpython / test_dsn

Method test_dsn

Lib/test/test_email/test_email.py:2581–2636  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2579 eq(submsg.get_payload(), 'Here is the body of the message.\n')
2580
2581 def test_dsn(self):
2582 eq = self.assertEqual
2583 # msg 16 is a Delivery Status Notification, see RFC 1894
2584 msg = self._msgobj('msg_16.txt')
2585 eq(msg.get_content_type(), 'multipart/report')
2586 self.assertTrue(msg.is_multipart())
2587 eq(len(msg.get_payload()), 3)
2588 # Subpart 1 is a text/plain, human readable section
2589 subpart = msg.get_payload(0)
2590 eq(subpart.get_content_type(), 'text/plain')
2591 eq(subpart.get_payload(), """\
2592This report relates to a message you sent with the following header fields:
2593
2594 Message-id: <002001c144a6$8752e060$56104586@oxy.edu>
2595 Date: Sun, 23 Sep 2001 20:10:55 -0700
2596 From: "Ian T. Henry" <henryi@oxy.edu>
2597 To: SoCal Raves <scr@socal-raves.org>
2598 Subject: [scr] yeah for Ians!!
2599
2600Your message cannot be delivered to the following recipients:
2601
2602 Recipient address: jangel1@cougar.noc.ucla.edu
2603 Reason: recipient reached disk quota
2604
2605""")
2606 # Subpart 2 contains the machine parsable DSN information. It
2607 # consists of two blocks of headers, represented by two nested Message
2608 # objects.
2609 subpart = msg.get_payload(1)
2610 eq(subpart.get_content_type(), 'message/delivery-status')
2611 eq(len(subpart.get_payload()), 2)
2612 # message/delivery-status should treat each block as a bunch of
2613 # headers, i.e. a bunch of Message objects.
2614 dsn1 = subpart.get_payload(0)
2615 self.assertIsInstance(dsn1, Message)
2616 eq(dsn1['original-envelope-id'], '0GK500B4HD0888@cougar.noc.ucla.edu')
2617 eq(dsn1.get_param('dns', header='reporting-mta'), '')
2618 # Try a missing one <wink>
2619 eq(dsn1.get_param('nsd', header='reporting-mta'), None)
2620 dsn2 = subpart.get_payload(1)
2621 self.assertIsInstance(dsn2, Message)
2622 eq(dsn2['action'], 'failed')
2623 eq(dsn2.get_params(header='original-recipient'),
2624 [('rfc822', ''), ('jangel1@cougar.noc.ucla.edu', '')])
2625 eq(dsn2.get_param('rfc822', header='final-recipient'), '')
2626 # Subpart 3 is the original message
2627 subpart = msg.get_payload(2)
2628 eq(subpart.get_content_type(), 'message/rfc822')
2629 payload = subpart.get_payload()
2630 self.assertIsInstance(payload, list)
2631 eq(len(payload), 1)
2632 subsubpart = payload[0]
2633 self.assertIsInstance(subsubpart, Message)
2634 eq(subsubpart.get_content_type(), 'text/plain')
2635 eq(subsubpart['message-id'],
2636 '<002001c144a6$8752e060$56104586@oxy.edu>')
2637
2638 def test_epilogue(self):

Callers

nothing calls this directly

Calls 9

eqFunction · 0.85
get_content_typeMethod · 0.80
assertTrueMethod · 0.80
is_multipartMethod · 0.80
get_payloadMethod · 0.80
assertIsInstanceMethod · 0.80
get_paramMethod · 0.80
get_paramsMethod · 0.80
_msgobjMethod · 0.45

Tested by

no test coverage detected