예제 #1
0
    def test_acquisition_notification(self):
        # Execute method
        handler = notification_handler.NotificationsHandler()
        handler.send_acquired_notification(self._order)

        # Validate calls
        self._validate_user_call()

        notification_handler.MIMEMultipart.assert_called_once_with()

        self.assertEquals(
            [
                call('Subject', 'Product order accepted'),
                call('From', '*****@*****.**'),
                call('To', '[email protected],[email protected]')
            ],
            notification_handler.MIMEMultipart().__setitem__.call_args_list)

        text = "We have received the payment of your order with reference orderid\n"
        text += "containing the following product offerings: \n\n"
        text += "Offering1 with id 1\n\n"
        text += "Offering2 with id 2\n\n"
        text += "You can review your orders at: \nhttp://localhost:8000/#/inventory/order\n"
        text += "and your acquired products at: \nhttp://localhost:8000/#/inventory/product\n"

        notification_handler.MIMEText.assert_called_once_with(text)

        self._validate_multipart_call()
        self._validate_email_call(notification_handler.MIMEMultipart)
    def _validate_multipart_call(self):
        self._mock_open.assert_called_once_with('/home/test/wstore/media/bills/bill1.pdf', 'rb')

        notification_handler.MIMEBase.assert_called_once_with('application', 'pdf')
        notification_handler.MIMEBase().set_payload.assert_called_once_with(self._mock_open().read())

        notification_handler.encoders.encode_base64.assert_called_once_with(notification_handler.MIMEBase())
        notification_handler.MIMEBase().add_header.assert_called_once_with(
            'Content-Disposition',
            'attachment',
            filename='bill1.pdf'
        )

        self.assertEquals([
            call(notification_handler.MIMEText()),
            call(notification_handler.MIMEBase())
        ], notification_handler.MIMEMultipart().attach.call_args_list)