Exemple #1
0
 def test_get_total_price_with_featured_item(self):
     cart = Cart(self.req)
     
     cat1 = mixer.blend(Category)
     book1 = create_book_instance()
     book2 = create_book_instance(category=cat1, featured=True, discount_price=500)
     cart.add(book1)
     cart.add(book2)
     self.assertEqual(cart.get_total_price(), sum([book1.price, book2.discount_price]))
Exemple #2
0
 def test_get_total_price_with_single_qty(self):
     cart = Cart(self.req)
     
     cat1 = mixer.blend(Category)
     book1 = create_book_instance()
     book2 = create_book_instance(category=cat1)
     cart.add(book1)
     cart.add(book2)
     
     self.assertEqual(cart.get_total_price(), sum([book1.price, book2.price]))
Exemple #3
0
 def test_can_remove_item_form_cart(self):
     cart = Cart(self.req)
     
     cat1 = mixer.blend(Category)
     book1 = create_book_instance()
     book2 = create_book_instance(category=cat1)
     cart.add(book1)
     cart.add(book2)
     cart.remove(book1)
     self.assertEqual(len(cart), 1)
     self.assertNotIn(str(book1.id), cart.cart.keys())
Exemple #4
0
 def test_can_add_multiple_items_to_cart(self):
     cart = Cart(self.req)
     
     cat1 = mixer.blend(Category)
     book1 = create_book_instance()
     book2 = create_book_instance(category=cat1)
     cart.add(book1)
     cart.add(book2)
     self.assertEqual(len(cart), 2)
     self.assertIn(str(book1.id), cart.cart.keys())
     self.assertIn(str(book2.id), cart.cart.keys())
Exemple #5
0
    def test_can_clear_cart(self):
        cart = Cart(self.req)
        
        cat1 = mixer.blend(Category)
        book1 = create_book_instance()
        book2 = create_book_instance(category=cat1)
        cart.add(book1, 3)
        cart.add(book2, 2)
        cart.clear()

        with pytest.raises(KeyError):
            self.assertFalse(cart.session[settings.CART_SESSION_ID])
Exemple #6
0
 def setUp(self):
     self.book = create_book_instance()
     self.req = RequestFactory().post(
         reverse_lazy("cart:cart_remove", args=[self.book.id]))
     middleware = SessionMiddleware()
     middleware.process_request(self.req)
     self.req.session.save()
Exemple #7
0
    def test_payment_payment_rejected(self, mock_Paystack):
        order = mixer.blend(Order)
        req = RequestFactory().post(
            reverse_lazy("orders:download", args=[order.id]))
        middleware = SessionMiddleware()
        middleware.process_request(req)
        req.session.save()
        # create a book instance and add it to cart
        book = create_book_instance()
        ct = Cart(req)
        ct.add(book)
        mock_Paystack(
            secret_key=settings.PAYSTACK_SECRET_KEY
        ).transaction.verify = MagicMock(
            return_value={
                'data': {
                    'status': 'failed',
                    'amount': ct.get_total_price() * 100,
                    'gateway_response': "payment was not successful"
                }
            })

        resp = confirm_payment(req, order.id)
        updated_order = Order.objects.first()
        self.assertFalse(updated_order.paid)
Exemple #8
0
 def test_get_total_cost(self):
     order = mixer.blend(Order)
     book = create_book_instance()
     order_item1 = mixer.blend(OrderItem,
                               order=order,
                               book=book,
                               quantity=1,
                               price=2000)
     order_item2 = mixer.blend(OrderItem,
                               order=order,
                               book=book,
                               quantity=1,
                               price=2500)
     order_item3 = mixer.blend(OrderItem,
                               order=order,
                               book=book,
                               quantity=1,
                               price=1000)
     self.assertEqual(
         order.get_total_cost(),
         sum([
             order_item1.get_cost(),
             order_item2.get_cost(),
             order_item3.get_cost()
         ]))
Exemple #9
0
 def test_can_add_one_item_to_cart(self):
     
     cart = Cart(self.req)
     
     book = create_book_instance()
     cart.add(book)
     self.assertEqual(len(cart), 1)
     self.assertIn(str(book.id), cart.cart.keys())
Exemple #10
0
 def test_auth_user_order_contains_order_items(self):
     req = RequestFactory().get(reverse_lazy("orders:order_create"))
     middleware = SessionMiddleware()
     middleware.process_request(req)
     req.session.save()
     # create a book instance and add it to cart
     book = create_book_instance()
     ct = Cart(req)
     ct.add(book)
     user = User.objects.create_user(username='******',
                                     email='*****@*****.**',
                                     password='******')
     req.user = user
     resp = order_create(req)
     order = Order.objects.first()
     self.assertGreaterEqual(order.items.count(), 1,
                             "Order should contain atleast one item")
Exemple #11
0
    def test_post_request(self):
        data = {
            "first_name": "Sam",
            'last_name': "James",
            "email": "*****@*****.**"
        }
        req = RequestFactory().post(reverse_lazy("orders:order_create"),
                                    data=data)
        middleware = SessionMiddleware()
        middleware.process_request(req)
        req.session.save()
        # create a book instance and add it to cart
        book = create_book_instance()
        ct = Cart(req)
        ct.add(book)

        resp = order_create(req)
        self.assertEqual(resp.status_code, 200)
        self.assertEqual(OrderItem.objects.count(), 1)
Exemple #12
0
 def setUp(self):
     self.order = mixer.blend(Order)
     self.book = create_book_instance()