Exemple #1
0
    def trigger_approved_tasks(self):
        #  Create task to associate student with calendar sent messages
        associate_student_to_messages_task = AssociateStudentToMessagesTask()

        # Create Balance log to organizer
        BalanceLog.create(organizer=self.organizer, order=self.order)

        # Crete task to recalculate organizer unavailable amount
        calculate_organizer_balance_task = CalculateOrganizerBalanceTask()

        # Send email about the payment (invoice)
        send_payment_email_task = SendPaymentEmailTask()

        # Send email to the organizer about the activity enrolled
        send_new_enrollment_email_task = SendNewEnrollmentEmailTask()

        # Referral coupon task
        #referral_coupon_task = ReferrerCouponTask()
        #create_coupon_task = CreateCouponTask()
        # send_coupon_email_task = SendCouponEmailTask()
        #
        group(
            associate_student_to_messages_task.s(self.calendar.id,
                                                 self.student_id),
            calculate_organizer_balance_task.s([self.organizer.id]),
            send_payment_email_task.s(self.order.id, self.task_data),
            send_new_enrollment_email_task.s(self.order.id, self.task_data),
            #     (
            #         referral_coupon_task.s(self.student_id, self.order.id) |
            #         create_coupon_task.s() |
            #         send_coupon_email_task.s()
            #     ),
        )()
Exemple #2
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())
Exemple #3
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())
Exemple #4
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())
Exemple #5
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())
Exemple #6
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())