def test_send_pse_order_approved(self, send_mail): """ Test task send the email successfully when: - the order is approved - the payment method is pse """ payment = PaymentFactory(payment_type='PSE') order = OrderFactory(status=Order.ORDER_APPROVED_STATUS, payment=payment) email = order.calendar.activity.organizer.user.email assistants = AssistantFactory.create_batch(1, order=order) send_mail.return_value = [{ 'email': email, 'status': 'sent', 'reject_reason': None }] task = SendNewEnrollmentEmailTask() 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/new_enrollment.html').exists())
def create_assistants(self): self.stdout.write('Creando assistants') assistants = list() for order in self.orders: quantity = self.get_quantity(range(1, order.quantity + 1)) assistants.append( AssistantFactory.create_batch(quantity, order=order)) return self.flat_list(assistants)
def setUp(self): self.organizer = OrganizerFactory() self.student = StudentFactory() self.calendar = CalendarFactory(activity__organizer=self.organizer) self.organizer_message = OrganizerMessageFactory( calendar=self.calendar) self.assistants = AssistantFactory.create_batch( size=3, order__calendar=self.calendar, order__student=self.student, order__status=Order.ORDER_APPROVED_STATUS, enrolled=True)
def setUp(self): self.organizer = OrganizerFactory() self.calendar = CalendarFactory(activity__organizer=self.organizer) self.organizer_message = OrganizerMessageFactory( calendar=self.calendar) self.orders = OrderFactory.create_batch( size=3, calendar=self.calendar, status=Order.ORDER_APPROVED_STATUS) self.assistants = [] for order in self.orders: self.assistants.append( AssistantFactory(order=order, email=order.student.user.email, enrolled=True))
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())
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())
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())
def setUp(self): super(PaymentWebHookWithCouponTest, self).setUp() # Objects self.calendar = CalendarFactory(session_price=100000.0, available_capacity=20, activity__published=True) self.redeem = mommy.make(Redeem, student=self.student, coupon__coupon_type__amount=50000) self.payment = mommy.make(Payment, payment_type=Payment.CC_PAYMENT_TYPE) self.order = mommy.make(Order, status=Order.ORDER_PENDING_STATUS, payment=self.payment, coupon=self.redeem.coupon, calendar=self.calendar, student=self.student) self.assistants = AssistantFactory.create_batch(3, order=self.order) self.post_data = self.get_post_data() # URLs self.payu_callback_url = reverse('payments:notification')
def setUp(self): self.calendar = CalendarFactory() self.order = OrderFactory(calendar=self.calendar, status=Order.ORDER_APPROVED_STATUS) self.assistants = AssistantFactory.create_batch(2, order=self.order)