Exemplo n.º 1
0
    def test_send_mail_failed(self, send_mail):
        """
        Test the task when the send_mail fails
        """
        payment = PaymentFactory(payment_type='CC', card_type='visa')
        order = OrderFactory(status=Order.ORDER_APPROVED_STATUS, payment=payment)

        send_mail.side_effect = Exception('Connection failed')

        task = SendPaymentEmailTask()
        task_id = task.delay(order.id)

        self.assertTrue(EmailTaskRecord.objects.filter(
            task_id=task_id,
            to=order.student.user.email,
            status='error',
            reject_reason='Connection failed').exists())
Exemplo n.º 2
0
    def test_send_pse_order_with_coupon_declined(self, send_mail):
        """
        Test task send the email successfully when:
        - the order is declined
        - the payment method is pse
        - the order has a coupon
        """

        student = StudentFactory()
        redeem = RedeemFactory(student=student, used=True)
        payment = PaymentFactory(payment_type='PSE')
        order = OrderFactory(status=Order.ORDER_DECLINED_STATUS, payment=payment,
                             student=student, coupon=redeem.coupon)
        email = order.student.user.email
        assistants = AssistantFactory.create_batch(1, order=order)
        transaction_error = 'ERROR'

        send_mail.return_value = [{
            'email': email,
            'status': 'sent',
            'reject_reason': None
        }]

        task = SendPaymentEmailTask()
        task_id = task.delay(order.id, transaction_error=transaction_error)

        context = {
            **self.get_context_data(order, assistants),
            'status': 'Declinada',
            'payment_type': 'PSE',
            'card_type': dict(Payment.CARD_TYPE)[payment.card_type],
            'coupon_amount': redeem.coupon.coupon_type.amount,
            'error': transaction_error,
        }

        self.assertTrue(EmailTaskRecord.objects.filter(
            task_id=task_id,
            to=email,
            status='sent',
            data=context,
            template_name='payments/email/payment_declined.html').exists())
Exemplo n.º 3
0
    def test_send_creditcard_with_coupon_order_approved(self, send_mail):
        """
        Test task send the email successfully when:
        - the order is approved
        - the payment method is credit card
        - the order has a coupon
        """

        student = StudentFactory()
        redeem = RedeemFactory(student=student, used=True)
        payment = PaymentFactory(payment_type='CC', card_type='visa')
        order = OrderFactory(status=Order.ORDER_APPROVED_STATUS, payment=payment,
                             student=student, coupon=redeem.coupon)
        email = order.student.user.email
        assistants = AssistantFactory.create_batch(1, order=order)

        send_mail.return_value = [{
            'email': email,
            'status': 'sent',
            'reject_reason': None
        }]

        task = SendPaymentEmailTask()
        task_id = task.delay(order.id)

        context = {
            **self.get_context_data(order, assistants),
            'status': 'Aprobada',
            'payment_type': 'Crédito',
            'card_type': 'VISA',
            'coupon_amount': redeem.coupon.coupon_type.amount,
        }

        self.assertTrue(EmailTaskRecord.objects.filter(
            task_id=task_id,
            to=email,
            status='sent',
            data=context,
            template_name='payments/email/payment_approved.html').exists())
Exemplo n.º 4
0
    def test_send_creditcard_order_without_coupon_declined(self, send_mail):
        """
        Test task send the email successfully when:
        - the order is declined
        - the payment method is credit card
        - the order doesn't have a coupon
        """

        payment = PaymentFactory(payment_type='CC', card_type='visa')
        order = OrderFactory(status=Order.ORDER_DECLINED_STATUS, payment=payment)
        email = order.student.user.email
        assistants = AssistantFactory.create_batch(1, order=order)
        transaction_error = 'ERROR'

        send_mail.return_value = [{
            'email': email,
            'status': 'sent',
            'reject_reason': None
        }]

        task = SendPaymentEmailTask()
        task_id = task.delay(order.id, transaction_error=transaction_error)

        context = {
            **self.get_context_data(order, assistants),
            'status': 'Declinada',
            'payment_type': 'Crédito',
            'card_type': 'VISA',
            'coupon_amount': None,
            'error': transaction_error,
        }

        self.assertTrue(EmailTaskRecord.objects.filter(
            task_id=task_id,
            to=email,
            status='sent',
            data=context,
            template_name='payments/email/payment_declined.html').exists())
Exemplo n.º 5
0
    def test_send_pse_without_coupon_order_approved(self, send_mail):
        """
        Test task send the email successfully when:
        - the order is approved
        - the payment method is pse
        - the order doesn't have a coupon
        """

        payment = PaymentFactory(payment_type='PSE')
        order = OrderFactory(status=Order.ORDER_APPROVED_STATUS, payment=payment)
        email = order.student.user.email
        assistants = AssistantFactory.create_batch(1, order=order)

        send_mail.return_value = [{
            'email': email,
            'status': 'sent',
            'reject_reason': None
        }]

        task = SendPaymentEmailTask()
        task_id = task.delay(order.id)

        context = {
            **self.get_context_data(order, assistants),
            'status': 'Aprobada',
            'payment_type': 'PSE',
            'card_type': dict(Payment.CARD_TYPE)[payment.card_type],
            'coupon_amount': None,
        }

        self.assertTrue(EmailTaskRecord.objects.filter(
            task_id=task_id,
            to=email,
            status='sent',
            data=context,
            template_name='payments/email/payment_approved.html').exists())