def test_signup_used(self): """ Test the used global signup coupon """ coupon = CouponFactory(coupon_type__type='global') coupon.token = 'GLOBAL-SIGNUP' coupon.save(update_fields=['token']) RedeemFactory(coupon=coupon, student=self.student, used=True) url = reverse('referrals:validate_coupon', kwargs={'coupon_code': 'GLOBAL-SIGNUP'}) response = self.student_client.get(url) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
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 setUp(self): # Arrangement self.redeem = RedeemFactory(coupon__coupon_type__name='referrer') self.email = self.redeem.student.user.email
def create_redeems(self): self.stdout.write('Creando redeems') coupon_type = CouponTypeFactory() return RedeemFactory(student=self.referral.referred, coupon__coupon_type=coupon_type)