Exemplo n.º 1
0
 def test_orderItem_purchased_callback(self):
     """
     This tests that calling purchased_callback on the base OrderItem class raises NotImplementedError
     """
     item = OrderItem(user=self.user, order=Order.get_cart_for_user(self.user))
     with self.assertRaises(NotImplementedError):
         item.purchased_callback()
Exemplo n.º 2
0
 def test_order_item_purchased_callback(self):
     """
     This tests that calling purchased_callback on the base OrderItem class raises NotImplementedError
     """
     item = OrderItem(user=self.user, order=Order.get_cart_for_user(self.user))
     with self.assertRaises(NotImplementedError):
         item.purchased_callback()
Exemplo n.º 3
0
 def test_purchased_items_btw_dates(self):
     purchases = OrderItem.purchased_items_btw_dates(self.now - self.FIVE_MINS, self.now + self.FIVE_MINS)
     self.assertEqual(len(purchases), 2)
     self.assertIn(self.reg.orderitem_ptr, purchases)
     self.assertIn(self.cert_item.orderitem_ptr, purchases)
     no_purchases = OrderItem.purchased_items_btw_dates(self.now + self.FIVE_MINS,
                                                        self.now + self.FIVE_MINS + self.FIVE_MINS)
     self.assertFalse(no_purchases)
Exemplo n.º 4
0
 def test_user_cart_has_items(self):
     anon = AnonymousUser()
     self.assertFalse(Order.user_cart_has_items(anon))
     self.assertFalse(Order.user_cart_has_items(self.user))
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(order=cart, user=self.user)
     item.save()
     self.assertTrue(Order.user_cart_has_items(self.user))
Exemplo n.º 5
0
 def test_user_cart_has_items(self):
     anon = AnonymousUser()
     self.assertFalse(Order.user_cart_has_items(anon))
     self.assertFalse(Order.user_cart_has_items(self.user))
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(order=cart, user=self.user)
     item.save()
     self.assertTrue(Order.user_cart_has_items(self.user))
Exemplo n.º 6
0
 def test_purchased_items_btw_dates(self):
     purchases = OrderItem.purchased_items_btw_dates(
         self.now - self.FIVE_MINS, self.now + self.FIVE_MINS)
     self.assertEqual(len(purchases), 2)
     self.assertIn(self.reg.orderitem_ptr, purchases)
     self.assertIn(self.cert_item.orderitem_ptr, purchases)
     no_purchases = OrderItem.purchased_items_btw_dates(
         self.now + self.FIVE_MINS,
         self.now + self.FIVE_MINS + self.FIVE_MINS)
     self.assertFalse(no_purchases)
Exemplo n.º 7
0
 def test_user_cart_has_items(self):
     anon = AnonymousUser()
     self.assertFalse(Order.user_cart_has_items(anon))
     self.assertFalse(Order.user_cart_has_items(self.user))
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(order=cart, user=self.user)
     item.save()
     self.assertTrue(Order.user_cart_has_items(self.user))
     self.assertFalse(Order.user_cart_has_items(self.user, CertificateItem))
     self.assertFalse(Order.user_cart_has_items(self.user, PaidCourseRegistration))
Exemplo n.º 8
0
 def test_user_cart_has_items(self):
     anon = AnonymousUser()
     self.assertFalse(Order.user_cart_has_items(anon))
     self.assertFalse(Order.user_cart_has_items(self.user))
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(order=cart, user=self.user)
     item.save()
     self.assertTrue(Order.user_cart_has_items(self.user))
     self.assertFalse(Order.user_cart_has_items(self.user, [CertificateItem]))
     self.assertFalse(Order.user_cart_has_items(self.user, [PaidCourseRegistration]))
Exemplo n.º 9
0
 def test_order_item_generate_receipt_instructions(self):
     """
     This tests that the generate_receipt_instructions call chain and also
     that calling it on the base OrderItem class returns an empty list
     """
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(user=self.user, order=cart)
     item.save()
     self.assertTrue(cart.has_items())
     (inst_dict, inst_set) = cart.generate_receipt_instructions()
     self.assertDictEqual({item.pk_with_subclass: set([])}, inst_dict)
     self.assertEquals(set([]), inst_set)
Exemplo n.º 10
0
 def test_generate_receipt_instructions_callchain(self):
     """
     This tests the generate_receipt_instructions call chain (ie calling the function on the
     cart also calls it on items in the cart
     """
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(user=self.user, order=cart)
     item.save()
     self.assertTrue(cart.has_items())
     with patch.object(OrderItem, 'generate_receipt_instructions', self.mock_gen_inst):
         cart.generate_receipt_instructions()
         self.mock_gen_inst.assert_called_with()
Exemplo n.º 11
0
 def test_order_item_generate_receipt_instructions(self):
     """
     This tests that the generate_receipt_instructions call chain and also
     that calling it on the base OrderItem class returns an empty list
     """
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(user=self.user, order=cart)
     item.save()
     self.assertTrue(cart.has_items())
     (inst_dict, inst_set) = cart.generate_receipt_instructions()
     self.assertDictEqual({item.pk_with_subclass: set([])}, inst_dict)
     self.assertEqual(set([]), inst_set)
Exemplo n.º 12
0
 def test_generate_receipt_instructions_callchain(self):
     """
     This tests the generate_receipt_instructions call chain (ie calling the function on the
     cart also calls it on items in the cart
     """
     cart = Order.get_cart_for_user(self.user)
     item = OrderItem(user=self.user, order=cart)
     item.save()
     self.assertTrue(cart.has_items())
     with patch.object(OrderItem, 'generate_receipt_instructions', self.mock_gen_inst):
         cart.generate_receipt_instructions()
         self.mock_gen_inst.assert_called_with()
Exemplo n.º 13
0
    def test_generate_receipt_instructions_callchain(self):
        """
        This tests the generate_receipt_instructions call chain (ie calling the function on the
        cart also calls it on items in the cart
        """
        mock_gen_inst = MagicMock(return_value=(OrderItemSubclassPK(OrderItem, 1), set([])))

        cart = Order.get_cart_for_user(self.user)
        item = OrderItem(user=self.user, order=cart)
        item.save()
        self.assertTrue(cart.has_items())
        with patch.object(OrderItem, 'generate_receipt_instructions', mock_gen_inst):
            cart.generate_receipt_instructions()
            mock_gen_inst.assert_called_with()
Exemplo n.º 14
0
    def test_generate_receipt_instructions_callchain(self):
        """
        This tests the generate_receipt_instructions call chain (ie calling the function on the
        cart also calls it on items in the cart
        """
        mock_gen_inst = MagicMock(return_value=(OrderItemSubclassPK(OrderItem, 1), set([])))

        cart = Order.get_cart_for_user(self.user)
        item = OrderItem(user=self.user, order=cart)
        item.save()
        self.assertTrue(cart.has_items())
        with patch.object(OrderItem, 'generate_receipt_instructions', mock_gen_inst):
            cart.generate_receipt_instructions()
            mock_gen_inst.assert_called_with()
Exemplo n.º 15
0
    def post(self,request):
        order = Order(customer=request.user.customer)
        customer = Customer.objects.get(user = request.user)
        cart_data = customer.cart
        total = 0
        for i, item in enumerate(cart_data):
            total = cart_data[i]['price']+total

        order.total_price = total
        order.save()

        for i, item in enumerate(cart_data):
            orderitem = OrderItem(order = order)
            product = Product.objects.get(id=cart_data[i]['product'])
            orderitem.product = product
            orderitem.quantity= cart_data[i]['quantity']
            orderitem.price = cart_data[i]['price']
            orderitem.save()

        del request.session['cartcount']
        customer.cart =[]
        customer.save()

        added = True
        return render(request,'checkout.html',{'added':added})
Exemplo n.º 16
0
    def test_purchased_csv(self):
        """
        Tests that a generated purchase report CSV is as we expect
        """
        # coerce the purchase times to self.test_time so that the test can match.
        # It's pretty hard to patch datetime.datetime b/c it's a python built-in, which is immutable, so we
        # make the times match this way
        for item in OrderItem.purchased_items_btw_dates(self.now - self.FIVE_MINS, self.now + self.FIVE_MINS):
            item.fulfilled_time = self.test_time
            item.save()

        # add annotation to the
        csv_file = StringIO.StringIO()
        OrderItem.csv_purchase_report_btw_dates(csv_file, self.now - self.FIVE_MINS, self.now + self.FIVE_MINS)
        csv = csv_file.getvalue()
        csv_file.close()
        # Using excel mode csv, which automatically ends lines with \r\n, so need to convert to \n
        self.assertEqual(csv.replace('\r\n', '\n').strip(), self.CORRECT_CSV.strip())
Exemplo n.º 17
0
 def test_report_csv(self):
     PaidCourseRegistration.add_to_order(self.cart, self.course_id)
     self.cart.purchase()
     self.login_user()
     self.add_to_download_group(self.user)
     response = self.client.post(reverse('payment_csv_report'), {'start_date': '1970-01-01',
                                                                 'end_date': '2100-01-01'})
     self.assertEqual(response['Content-Type'], 'text/csv')
     self.assertIn(",".join(OrderItem.csv_report_header_row()), response.content)
     self.assertIn(self.CORRECT_CSV_NO_DATE, response.content)
Exemplo n.º 18
0
    def test_render_purchase_form_html(self, render):
        """
        Tests the rendering of the purchase form
        """
        student1 = UserFactory()
        student1.save()

        order1 = Order.get_cart_for_user(student1)
        item1 = OrderItem(order=order1, user=student1, unit_cost=1.0, line_cost=1.0)
        item1.save()
        render_purchase_form_html(order1)
        ((template, context), render_kwargs) = render.call_args

        self.assertEqual(template, 'shoppingcart/cybersource_form.html')
        self.assertDictContainsSubset({'amount': '1.00',
                                       'currency': 'usd',
                                       'orderPage_transactionType': 'sale',
                                       'orderNumber': str(order1.id)},
                                      context['params'])
Exemplo n.º 19
0
    def test_get_list_price(self):
        """
        This tests the get_list_price() method of the OrderItem
        """
        cart = Order.get_cart_for_user(self.user)
        item = OrderItem(user=self.user, order=cart)

        item.list_price = None
        item.unit_cost = 100
        self.assertEqual(item.get_list_price(), item.unit_cost)

        item.list_price = 200
        item.unit_cost = 100
        self.assertEqual(item.get_list_price(), item.list_price)
Exemplo n.º 20
0
 def test_report_csv(self):
     PaidCourseRegistration.add_to_order(self.cart, self.course_id)
     self.cart.purchase()
     self.login_user()
     self.add_to_download_group(self.user)
     response = self.client.post(reverse('payment_csv_report'), {
         'start_date': '1970-01-01',
         'end_date': '2100-01-01'
     })
     self.assertEqual(response['Content-Type'], 'text/csv')
     self.assertIn(",".join(OrderItem.csv_report_header_row()),
                   response.content)
     self.assertIn(self.CORRECT_CSV_NO_DATE, response.content)
Exemplo n.º 21
0
    def test_purchased_csv(self):
        """
        Tests that a generated purchase report CSV is as we expect
        """
        # coerce the purchase times to self.test_time so that the test can match.
        # It's pretty hard to patch datetime.datetime b/c it's a python built-in, which is immutable, so we
        # make the times match this way
        for item in OrderItem.purchased_items_btw_dates(
                self.now - self.FIVE_MINS, self.now + self.FIVE_MINS):
            item.fulfilled_time = self.test_time
            item.save()

        # add annotation to the
        csv_file = StringIO.StringIO()
        OrderItem.csv_purchase_report_btw_dates(csv_file,
                                                self.now - self.FIVE_MINS,
                                                self.now + self.FIVE_MINS)
        csv = csv_file.getvalue()
        csv_file.close()
        # Using excel mode csv, which automatically ends lines with \r\n, so need to convert to \n
        self.assertEqual(
            csv.replace('\r\n', '\n').strip(), self.CORRECT_CSV.strip())
Exemplo n.º 22
0
    def test_is_discounted(self):
        """
        This tests the is_discounted property of the OrderItem
        """
        cart = Order.get_cart_for_user(self.user)
        item = OrderItem(user=self.user, order=cart)

        item.list_price = None
        item.unit_cost = 100
        self.assertFalse(item.is_discounted)

        item.list_price = 100
        item.unit_cost = 100
        self.assertFalse(item.is_discounted)

        item.list_price = 100
        item.unit_cost = 90
        self.assertTrue(item.is_discounted)