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))
Example #2
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]))
Example #3
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]))
 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)
 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()
Example #6
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)
Example #7
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()
Example #8
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()
Example #9
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()
Example #10
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'])