'Test that a C{MAIL FROM} command with an address rejected by a
L{smtp.IMessageDelivery} instance is responded to with the correct
error code.'

def test_deliveryRejectedSenderAddress(self):

    class RejectionDelivery(NotImplementedDelivery, ):
        '\n                                                Delivery    object    which    rejects    all    senders    as    invalid.\n                                                '
        def validateFrom(self, helo, origin):
            raise smtp.SMTPBadSender(origin)
    realm = SingletonRealm(smtp.IMessageDelivery, RejectionDelivery())
    portal = Portal(realm, [AllowAnonymousAccess()])
    proto = smtp.SMTP()
    proto.portal = portal
    trans = StringTransport()
    proto.makeConnection(trans)
    proto.dataReceived('HELO    example.com\r\n')
    trans.clear()
    proto.dataReceived('MAIL    FROM:<alice@example.com>\r\n')
    proto.connectionLost(error.ConnectionLost())
    self.assertEqual(trans.value(), '550    Cannot    receive    from    specified    address    <alice@example.com>:    Sender    not    acceptable\r\n')
