Exemplo n.º 1
0
    def test_signup_username_already_exists(self, get_json, send_mail, delay):
        StudentFactory(user__username='******')
        user_counter = User.objects.count()

        get_json.return_value = {
            'email': '*****@*****.**',
            'first_name': 'Geralt',
            'last_name': 'De Rivia',
            'gender': 'male',
            'id': '123456789',
            'link': 'https://www.facebook.com/app_scoped_user_id/123456789',
            'locale': 'en_US',
            'name': 'Geralt De Rivia',
            'timezone': -5,
            'verified': True,
        }

        response = self.client.post(
            self.url,
            data={
                'access_token':
                'CAAYLX4HwZA38BAGjNLbUWhkBZBFR0HSDn9criXoxNUzjT'
            })

        student = Student.objects.last()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(User.objects.count(), user_counter + 1)
        self.assertEqual(student.user.username, 'geralt.derivia2')
Exemplo n.º 2
0
    def test_dont_create_referral_if_exists(self, get_json):
        get_json.return_value = {
            'email': '*****@*****.**',
            'first_name': 'Geralt',
            'last_name': 'De Rivia',
            'gender': 'male',
            'id': '123456789',
            'name': 'Geralt De Rivia',
        }

        student = StudentFactory()
        Token.objects.create(user=student.user)
        UserSocialAuth.objects.create(user=student.user,
                                      uid='123456789',
                                      provider='facebook')
        Referral.objects.create(referrer=self.student,
                                referred=student,
                                ip_address='127.0.0.1')

        # Counters
        referral_counter = Referral.objects.count()
        redeem_counter = Coupon.objects.count()

        # Cookies
        self.client.cookies['refhash'] = self.student.get_referral_hash()

        self.client.post(
            self.social_login_signup_url,
            {'access_token': 'CAAYLX4HwZA38BAGjNLbUWhkBZBFR0HSDn9criXoxNUzjT'})
        self.assertEqual(Referral.objects.count(), referral_counter)
        self.assertEqual(Coupon.objects.count(), redeem_counter)
        self.assertFalse(
            Redeem.objects.filter(
                student=student,
                coupon__coupon_type__name='referred').exists())
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
    def setUp(self):
        # Users
        self.password = '******'
        self.student = StudentFactory(user__password=self.password)
        self.organizer = OrganizerFactory(user__password=self.password)

        # Tokens
        self.student_token = Token.objects.create(user=self.student.user)
        self.organizer_token = Token.objects.create(user=self.organizer.user)

        # URL
        self.url = reverse('auth:login')
Exemplo n.º 5
0
    def setUp(self):
        # Users
        self.student, self.another_student = StudentFactory.create_batch(2)
        self.organizer, self.another_organizer = OrganizerFactory.create_batch(
            2)

        # API Clients
        self.student_client = self.get_client(user=self.student.user)
        self.organizer_client = self.get_client(user=self.organizer.user)
        self.another_student_client = self.get_client(
            user=self.another_student.user)
        self.another_organizer_client = self.get_client(
            user=self.another_organizer.user)
Exemplo n.º 6
0
    def test_login_success(self, get_json, send_mail):
        """
        Test social login for student
        """

        student = StudentFactory(user__first_name='Geralt',
                                 user__last_name='De Rivia',
                                 user__email='*****@*****.**')
        token = Token.objects.create(user=student.user)
        UserSocialAuth.objects.create(user=student.user,
                                      uid='123456789',
                                      provider='facebook')
        user_counter = User.objects.count()

        get_json.return_value = {
            'email': '*****@*****.**',
            'first_name': 'Geralt',
            'last_name': 'De Rivia',
            'gender': 'male',
            'id': '123456789',
            'link': 'https://www.facebook.com/app_scoped_user_id/123456789',
            'locale': 'en_US',
            'name': 'Geralt De Rivia',
            'timezone': -5,
            'verified': True,
        }

        response = self.client.post(
            self.url,
            data={
                'access_token':
                'CAAYLX4HwZA38BAGjNLbUWhkBZBFR0HSDn9criXoxNUzjT'
            })

        content = {
            'user': StudentsSerializer(student).data,
            'token': token.key,
        }

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(User.objects.count(), user_counter)
        self.assertEqual(response.data, content)
Exemplo n.º 7
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.º 8
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())
def insert_school_student_data(apps, _):
    schools = SchoolFactory.create_batch(5)
    _ = [
        StudentFactory.create_batch(5, school=school)
        for school in schools
    ]
Exemplo n.º 10
0
 def setUp(self):
     self.url = reverse('auth:confirm_email')
     self.student = StudentFactory(user__email='*****@*****.**')
Exemplo n.º 11
0
 def setUp(self):
     # Arrangement
     self.student = StudentFactory()
     self.order = OrderFactory(amount=500, student=self.student)
Exemplo n.º 12
0
 def setUp(self):
     self.organizer = OrganizerFactory()
     self.students = StudentFactory.create_batch(2)
     self.calendar = CalendarFactory(activity__organizer=self.organizer)
Exemplo n.º 13
0
 def create_students(self):
     self.stdout.write('Creando students')
     params = {'city': self.city} if self.city else {}
     return StudentFactory.create_batch(self.get_quantity(), **params)