Exemplo n.º 1
0
  def test_uid(self):
    email = "*****@*****.**"
    paypal_email = "*****@*****.**"
    q1 = Q(email__in=[email,paypal_email])
    q2 = Q(paypal_email__in=[email,paypal_email])
    get_user_model().objects.filter(q1|q2).delete()
    user = get_user_model().objects.create(
      username="******",
      email=email
    )
    user.set_password(user.email)
    user.save()

    client = Client()
    client.post(reverse('login'),{'username': email,'password': email})

    # buy a class while logged in
    invoice = add_to_cart(client,self.session1.sessionproduct,1)
    params = get_course_query(session=self.session1,payer_email=paypal_email,custom=user.pk,invoice=invoice)
    paypal_post(self,params)

    # no new counts should have been created and the user now has enrollments/paypal_email
    user = get_user_model().objects.get(email=email) # refresh instance
    self.assertEqual(get_user_model().objects.filter(q1|q2).count(),1)
    self.assertEqual(self.session1.enrollment_set.get(user=user).quantity,1)
    self.assertEqual(user.paypal_email,paypal_email)
Exemplo n.º 2
0
    def test_paypal_email(self):
        email = "*****@*****.**"
        get_user_model().objects.filter(email=email).delete()

        invoice = self.add_to_cart(self.session1.sessionproduct)
        # test first with no account
        params = get_course_query(session=self.session1,
                                  payer_email=email,
                                  invoice=invoice)
        paypal_post(self, params)

        # make sure only these two emails were sent to only that one address
        self.check_subjects(
            ["Course enrollment confirmation", "New account information"])
        for message in mail.outbox:
            self.assertEqual([email], message.recipients())

        # now test same address with another class
        mail.outbox = []
        invoice = self.add_to_cart(self.session2.sessionproduct, 1)
        params = get_course_query(session=self.session2,
                                  payer_email=email,
                                  invoice=invoice)
        paypal_post(self, params)
        self.check_subjects(["Course enrollment confirmation"])
        for message in mail.outbox:
            self.assertEqual([email], message.recipients())

        # make sure a new account is not created and that the enrollments are right
        self.assertEqual(get_user_model().objects.filter(email=email).count(),
                         1)
        # Note these next two lines use "get" because more than one enrollment throws an error.
        self.assertEqual(self.session1.enrollment_set.get().user.email, email)
        self.assertEqual(self.session2.enrollment_set.get().user.email, email)
Exemplo n.º 3
0
  def test_paypal_email(self):
    email = "*****@*****.**"
    get_user_model().objects.filter(email=email).delete()
    client = Client()

    invoice = add_to_cart(client,self.session1.sessionproduct,1)
    # test first with no account
    params = get_course_query(session=self.session1,payer_email=email,invoice=invoice)
    paypal_post(self,params)

    # make sure only these two emails were sent to only that one address
    self.assertTrue(check_subjects(["Course enrollment confirmation","New account information"]))
    for message in mail.outbox:
      self.assertEqual([email], message.recipients())

    # now test same address with another class
    mail.outbox = []
    invoice = add_to_cart(client,self.session2.sessionproduct,1)
    params = get_course_query(session=self.session2,payer_email=email,invoice=invoice)
    paypal_post(self,params)
    self.assertTrue(check_subjects(["Course enrollment confirmation"]))
    for message in mail.outbox:
      self.assertEqual([email], message.recipients())

    # make sure a new account is not created and that the enrollments are right
    self.assertEqual(get_user_model().objects.filter(email=email).count(),1)
    # Note these next two lines use "get" because more than one enrollment throws an error.
    self.assertEqual(Enrollment.objects.get(session=self.session1).user.email,email)
    self.assertEqual(Enrollment.objects.get(session=self.session2).user.email,email)
Exemplo n.º 4
0
    def test_quantity(self):
        """
    Pay for a class with more than one quantity. Make sure enrollment and session.total students is correct
    Pay for a class that the user is already enrolled in. ibid.
    """
        email = "*****@*****.**"
        paypal_email = "*****@*****.**"
        q1 = Q(email__in=[email, paypal_email])
        q2 = Q(paypal_email__in=[email, paypal_email])
        get_user_model().objects.filter(q1 | q2).delete()
        user = get_user_model().objects.create(username="******",
                                               email=email)
        params = get_course_query(session=self.session1,
                                  quantities=[2],
                                  payer_email=email)
        paypal_post(self, params)

        enrollment = self.session1.enrollment_set.get()
        self.assertEqual(enrollment.quantity, 2)
        self.assertEqual(enrollment.user, user)

        params = get_course_query(session=self.session1,
                                  quantities=[1],
                                  payer_email=email)
        paypal_post(self, params)

        enrollment = self.session1.enrollment_set.get()
        self.assertEqual(enrollment.quantity, 3)
        self.assertEqual(enrollment.user, user)
Exemplo n.º 5
0
  def test_quantity(self):
    """
    Pay for a class with more than one quantity. Make sure enrollment and session.total students is correct
    Pay for a class that the user is already enrolled in. ibid.
    """
    email = "*****@*****.**"
    paypal_email = "*****@*****.**"
    user = self.new_user(username=email)
    self.login(user)

    # create cart with cart_item
    invoice = self.add_to_cart(self.session1.sessionproduct,2)

    # fake the IPN
    params = get_course_query(session=self.session1,quantities=[2],payer_email=email,invoice=invoice)
    paypal_post(self,params)

    # Did it work?
    enrollment = self.session1.enrollment_set.get()
    self.assertEqual(enrollment.quantity,2)
    self.assertEqual(enrollment.user,user)

    # Lets do it again with 1 enrollment...
    invoice = self.add_to_cart(self.session1.sessionproduct)
    params = get_course_query(session=self.session1,quantities=[1],payer_email=email,invoice=invoice)
    paypal_post(self,params)

    # ...and see if the enrollment increased
    enrollment = self.session1.enrollment_set.get()
    self.assertEqual(enrollment.quantity,3)
    self.assertEqual(enrollment.user,user)
Exemplo n.º 6
0
  def setUp(self):
    # create user and give him a hacker membership, this should generate a safety criterion
    self.email = '*****@*****.**'
    level = Level.objects.get(name="Hacker")
    product = level.product_set.all()[0]
    data = get_membership_query(product=product,payer_email=self.email)
    paypal_post(self,data)

    #! TODO this is bad for now should not need to delete an entire set of courses just for this
    Session.objects.filter(course_id=settings.SAFETY_ID).delete()
    Flag.objects.all().delete()
    self.session = Session.objects.create(course_id=settings.SAFETY_ID,user_id=1)
Exemplo n.º 7
0
    def setUp(self):
        # create user and give him a hacker membership, this should generate a safety criterion
        self.email = '*****@*****.**'
        level = Level.objects.get(name="Hacker")
        product = level.product_set.all()[0]
        data = get_membership_query(product=product, payer_email=self.email)
        paypal_post(self, data)

        #! TODO this is bad for now should not need to delete an entire set of courses just for this
        Session.objects.filter(course_id=settings.SAFETY_ID).delete()
        Flag.objects.all().delete()
        self.session = Session.objects.create(course_id=settings.SAFETY_ID,
                                              user_id=1)
Exemplo n.º 8
0
    def test_discount(self):
        email = "*****@*****.**"
        get_user_model().objects.filter(email=email).delete()
        user = get_user_model().objects.create(username="******",
                                               email=email)
        user.level = Level.objects.filter(discount_percentage=10)[0]
        user.save()
        params = get_course_query(session=self.session1,
                                  quantities=[1],
                                  payer_email=email)
        paypal_post(self, params)

        # The above generates an enrollment error because someone over paid
        self.assertTrue(check_subjects(["Course enrollment confirmation"]))
Exemplo n.º 9
0
  def test_uid(self):
    username = "******"
    paypal_email = "*****@*****.**"
    user = self.new_user(username)
    self.login(user)

    # buy a class while logged in
    invoice = self.add_to_cart(self.session1.sessionproduct)
    params = get_course_query(session=self.session1,payer_email=paypal_email,custom=user.pk,invoice=invoice)
    paypal_post(self,params)

    # no new counts should have been created and the user now has enrollments/paypal_email
    user = get_user_model().objects.get(email=user.email) # refresh instance
    q1 = Q(email__in=[user.email,paypal_email])
    q2 = Q(paypal_email__in=[user.email,paypal_email])
    self.assertEqual(get_user_model().objects.filter(q1|q2).count(),1)
    self.assertEqual(self.session1.enrollment_set.get(user=user).quantity,1)
    self.assertEqual(user.paypal_email,paypal_email)
Exemplo n.º 10
0
  def test_quantity(self):
    """
    Pay for a class with more than one quantity. Make sure enrollment and session.total students is correct
    Pay for a class that the user is already enrolled in. ibid.
    """
    email = "*****@*****.**"
    paypal_email = "*****@*****.**"
    q1 = Q(email__in=[email,paypal_email])
    q2 = Q(paypal_email__in=[email,paypal_email])
    get_user_model().objects.filter(q1|q2).delete()
    user = get_user_model().objects.create(
      username="******",
      email=email
    )
    user.set_password(email)
    user.save()
    client = Client()

    #login user
    client.post(reverse('login'),{'username': email,'password': email})

    # create cart with cart_item
    invoice = add_to_cart(client,self.session1.sessionproduct,2)

    # fake the IPN
    params = get_course_query(session=self.session1,quantities=[2],payer_email=email,invoice=invoice)
    paypal_post(self,params)

    # Did it work?
    enrollment = self.session1.enrollment_set.get()
    self.assertEqual(enrollment.quantity,2)
    self.assertEqual(enrollment.user,user)

    # Lets do it again with 1 enrollment...
    invoice = add_to_cart(client,self.session1.sessionproduct,1)
    params = get_course_query(session=self.session1,quantities=[1],payer_email=email,invoice=invoice)
    paypal_post(self,params)

    # ...and see if the enrollment increased
    enrollment = self.session1.enrollment_set.get()
    self.assertEqual(enrollment.quantity,3)
    self.assertEqual(enrollment.user,user)
Exemplo n.º 11
0
  def test_discount(self):
    from paypal.standard.ipn.models import PayPalIPN
    email = "*****@*****.**"
    get_user_model().objects.filter(email=email).delete()
    user = get_user_model().objects.create(
      username="******",
      email=email
    )
    user.level = self.level10
    user.save()
    self.login(user)

    # create cart with cart_item
    invoice = self.add_to_cart(self.session1.sessionproduct)

    params = get_course_query(session=self.session1,quantities=[1],payer_email=email,invoice=invoice)
    paypal_post(self,params)

    # The above generates an enrollment error because someone over paid
    self.check_subjects(["Course enrollment confirmation"])
Exemplo n.º 12
0
    def test_discount(self):
        from paypal.standard.ipn.models import PayPalIPN
        email = "*****@*****.**"
        get_user_model().objects.filter(email=email).delete()
        user = get_user_model().objects.create(username="******",
                                               email=email)
        user.level = self.level10
        user.save()
        self.login(user)

        # create cart with cart_item
        invoice = self.add_to_cart(self.session1.sessionproduct)

        params = get_course_query(session=self.session1,
                                  quantities=[1],
                                  payer_email=email,
                                  invoice=invoice)
        paypal_post(self, params)

        # The above generates an enrollment error because someone over paid
        self.check_subjects(["Course enrollment confirmation"])
Exemplo n.º 13
0
    def test_uid(self):
        email = "*****@*****.**"
        paypal_email = "*****@*****.**"
        q1 = Q(email__in=[email, paypal_email])
        q2 = Q(paypal_email__in=[email, paypal_email])
        get_user_model().objects.filter(q1 | q2).delete()
        user = get_user_model().objects.create(username="******",
                                               email=email)

        # buy a class while logged in
        params = get_course_query(session=self.session1,
                                  payer_email=paypal_email,
                                  custom=user.pk)
        paypal_post(self, params)

        # no new counts should have been created and the user now has enrollments/paypal_email
        user = get_user_model().objects.get(email=email)  # refresh instance
        self.assertEqual(get_user_model().objects.filter(q1 | q2).count(), 1)
        self.assertEqual(
            self.session1.enrollment_set.get(user=user).quantity, 1)
        self.assertEqual(user.paypal_email, paypal_email)
Exemplo n.º 14
0
    def test_uid(self):
        username = "******"
        paypal_email = "*****@*****.**"
        user = self.new_user(username)
        self.login(user)

        # buy a class while logged in
        invoice = self.add_to_cart(self.session1.sessionproduct)
        params = get_course_query(session=self.session1,
                                  payer_email=paypal_email,
                                  custom=user.pk,
                                  invoice=invoice)
        paypal_post(self, params)

        # no new counts should have been created and the user now has enrollments/paypal_email
        user = get_user_model().objects.get(
            email=user.email)  # refresh instance
        q1 = Q(email__in=[user.email, paypal_email])
        q2 = Q(paypal_email__in=[user.email, paypal_email])
        self.assertEqual(get_user_model().objects.filter(q1 | q2).count(), 1)
        self.assertEqual(
            self.session1.enrollment_set.get(user=user).quantity, 1)
        self.assertEqual(user.paypal_email, paypal_email)
Exemplo n.º 15
0
    def test_quantity(self):
        """
    Pay for a class with more than one quantity. Make sure enrollment and session.total students is correct
    Pay for a class that the user is already enrolled in. ibid.
    """
        email = "*****@*****.**"
        paypal_email = "*****@*****.**"
        user = self.new_user(username=email)
        self.login(user)

        # create cart with cart_item
        invoice = self.add_to_cart(self.session1.sessionproduct, 2)

        # fake the IPN
        params = get_course_query(session=self.session1,
                                  quantities=[2],
                                  payer_email=email,
                                  invoice=invoice)
        paypal_post(self, params)

        # Did it work?
        enrollment = self.session1.enrollment_set.get()
        self.assertEqual(enrollment.quantity, 2)
        self.assertEqual(enrollment.user, user)

        # Lets do it again with 1 enrollment...
        invoice = self.add_to_cart(self.session1.sessionproduct)
        params = get_course_query(session=self.session1,
                                  quantities=[1],
                                  payer_email=email,
                                  invoice=invoice)
        paypal_post(self, params)

        # ...and see if the enrollment increased
        enrollment = self.session1.enrollment_set.get()
        self.assertEqual(enrollment.quantity, 3)
        self.assertEqual(enrollment.user, user)
Exemplo n.º 16
0
  def test_discount(self):
    from paypal.standard.ipn.models import PayPalIPN
    email = "*****@*****.**"
    get_user_model().objects.filter(email=email).delete()
    user = get_user_model().objects.create(
      username="******",
      email=email
    )
    user.level = Level.objects.filter(discount_percentage=10)[0]
    user.save()
    client = Client()

    #login user
    client.post(reverse('login'),{'username': email,'password': email})

    # create cart with cart_item
    invoice = add_to_cart(client,self.session1.sessionproduct,1)

    params = get_course_query(session=self.session1,quantities=[1],payer_email=email,invoice=invoice)
    print params['mc_gross']
    paypal_post(self,params)

    # The above generates an enrollment error because someone over paid
    self.assertTrue(check_subjects(["Course enrollment confirmation"]))