예제 #1
0
 def test_buy_hammer_get_nails_example(self):
     """Test the example as described in the docs
     /signals.html#an-example-of-post-add-to-basket"""
     # make the products
     hammer = SimpleProduct(
         title="Hammer",
         price="4.99")
     hammer.save()
     nails = SimpleProduct(
         title="Bag of 500 Nails",
         price="1.99")
     nails.save()
     #
     def free_nails_with_every_hammer(sender,
                     instance,
                     basketitem,
                     **kwargs):
         if basketitem.content_object.title == 'Hammer':
             nails = SimpleProduct.objects.get(title="Bag of 500 Nails")
             instance.add(nails,
                         price=Decimal("0.00"),
                         description="Free nails with every hammer",
                         silent=True,
                         locked=True)
     # connect signal
     post_add_to_basket.connect(free_nails_with_every_hammer,
         dispatch_uid='free_nails')
     # basket has zero
     self.assertEqual(0, self.basket.total_items())
     # add hammer
     basketitem = self.basket.add(hammer)
     # now have two items
     self.assertEqual(2, self.basket.total_items())
     # 1st: hammer, 1 , 4.99, locked=False
     self.assertEqual(
         self.basket.basketitem_set.all()[0].description,
         "Hammer")
     self.assertEqual(1, self.basket.basketitem_set.filter(
                 description="Hammer").count())
     self.assertEqual(
         self.basket.basketitem_set.all()[0].price,
         Decimal("4.99"))
     self.assertEqual(
         self.basket.basketitem_set.all()[0].locked,
         False)
     # 2nd: free nails, 1 , 0.00, locked=True
     self.assertEqual(
         self.basket.basketitem_set.all()[1].description,
         "Free nails with every hammer")
     self.assertEqual(1, self.basket.basketitem_set.filter(
                 description="Free nails with every hammer").count())
     self.assertEqual(
         self.basket.basketitem_set.all()[1].price,
         Decimal("0.00"))
     self.assertEqual(
         self.basket.basketitem_set.all()[1].locked,
         True)
     # disconnect
     post_add_to_basket.disconnect(dispatch_uid='free_nails')
예제 #2
0
 def test_buy_one_get_one_free_example(self):
     """Test as described in the docs
     /signals.html#an-example-of-pre-add-to-basket"""
     # make the product
     hammer = SimpleProduct(
         title="Hammer",
         price="4.99")
     hammer.save()
     # define the receiver
     def example_buy_one_get_one_free(sender,
                 instance,
                 item,
                 quantity,
                 **kwargs):
         # insert a hammer, with title 'buy one get one free' and a price
         # of 0.00
         if item.name == "Hammer":
             instance.add(hammer,
                     price="0.00",
                     description="Free Hammer! Buy One Get One Free",
                     locked=True,
                     silent=True)
     # connect it
     pre_add_to_basket.connect(example_buy_one_get_one_free,
         dispatch_uid='bogof')
     # our basket has no items
     self.assertEqual(0, self.basket.total_items())
     # add one hammer, quantity of one assumed by add method
     basketitem = self.basket.add(hammer)
     # now we have two basketitems
     self.assertEqual(2, self.basket.total_items())
     # The first is the free hammer
     self.assertEqual(
         self.basket.basketitem_set.all()[0].description,
         "Free Hammer! Buy One Get One Free")
     self.assertEqual(
         self.basket.basketitem_set.all()[0].price,
         Decimal("0.00"))
     # it's locked so the user can't mess with it
     self.assertEqual(
         self.basket.basketitem_set.all()[0].locked,
         True)
     # second is the paid for hammer
     self.assertEqual(
         self.basket.basketitem_set.all()[1].description,
         "Hammer")
     self.assertEqual(
         self.basket.basketitem_set.all()[1].price,
         Decimal("4.99"))
     self.assertEqual(
         self.basket.basketitem_set.all()[1].locked,
         False)
     # disconnect it
     pre_add_to_basket.disconnect('bogof')
예제 #3
0
 def setUp(self):
     # make a product
     item = SimpleProduct()
     item.price = Decimal("199.99")
     item.title = 'Yamaha Manu Katché Signature Junior Hip Gig Kit in Black'
     item.description = "Manu Katché famous for playing drums for the likes of Peter Gabriel and Sting announced to Yamaha \"Why don't you make a real drum kit for kids?\" The design team for Yamaha got to work and here are the results. A fantastic Philippine mahogany shell drum kit that delivers a loud, warm and an open tone. The bass drum is made from 9 ply while the toms and snare drum are made up from 6-ply. Each ply is laminated together using the exclusive Air Seal System ensuring that every shell is a uniform thickness. Finished off with a tough and very durable lacquer. This is an ideal drum kit for a beginner to the professional. Due to its sizes this drum kit can fit into most rooms without taking up too much room making this a perfect compact portable/practice drum kit"
     item.save()
     self.item = item
     # get the basket
     r = self.client.get(reverse('ccbasket:basket'))
     self.basket = self.client.session['basket']
예제 #4
0
 def setUp(self):
     # create a simple product
     item = SimpleProduct()
     item.price = Decimal("9.99")
     item.title = 'Another Product'
     item.save()
     self.item = item
     # get the ctype
     self.ctype = ContentType.objects.get(
                 app_label=self.item._meta.app_label,
                 model=self.item._meta.object_name.lower())
     # get the basket
     self.client.get(reverse('ccbasket:basket'))
     self.basket = self.client.session['basket']
예제 #5
0
 def setUp(self):
     # set up the test list as empty dict
     global test_dict
     test_dict = {}
     # define a product to use
     item = SimpleProduct()
     item.price = Decimal("199.99")
     item.title = 'Test Product'
     item.save()
     self.item = item
     # get the basket
     r = self.client.get(reverse('ccbasket:basket'))
     self.basket = self.client.session['basket']
     # delete cache
     self.basket._delete_cache()
 def setUp(self):
     # create a product to use
     item = SimpleProduct()
     item.price = Decimal("199.99")
     item.title = 'Test Product'
     item.save()
     self.item = item
     # get the ctype
     self.ctype = ContentType.objects.get(
                 app_label=self.item._meta.app_label,
                 model=self.item._meta.object_name.lower())
     # get a basket
     r = self.client.get(reverse('ccbasket:basket'))
     # request factory
     self.factory = RequestFactory()
예제 #7
0
 def setUp(self):
     # make a product
     item = SimpleProduct()
     item.price = Decimal("199.99")
     item.title = 'Test Product'
     item.save()
     self.item = item
     # 
     item2 = SimpleProduct()
     item2.price = Decimal("9.99")
     item2.title = 'Another Product'
     item2.save()
     self.item2 = item2
     # get the basket
     r = self.client.get(reverse('ccbasket:basket'))
     self.basket = self.client.session['basket']
 def setUp(self):
     # make the first product
     item = SimpleProduct()
     item.price = Decimal('199.99')
     item.title = 'Test Product'
     item.save()
     self.item = item
     # Make the second product
     item2 = SimpleProduct()
     item2.price = Decimal('9.99')
     item2.title = 'Another Product'
     item2.save()
     self.item2 = item2
     # get the basket
     self.client.get('/')
     self.basket = self.client.session['basket']
예제 #9
0
 def test_do_not_add(self):
     # make the products
     hammer = SimpleProduct(
         title="Hammer",
         price="4.99")
     hammer.save()
     # crude receiver
     def do_not_add(sender,instance, **kwargs):
         return {'do_not_add' : True}
     # connect it
     pre_add_to_basket.connect(do_not_add, dispatch_uid='do_not_add')
     # add to basket - None
     basketitem = self.basket.add(hammer)
     self.assertEqual(0, self.basket.total_items())
     # disconnect it
     pre_add_to_basket.disconnect(dispatch_uid='do_not_add')
     # add to basket now and it will go in
     basketitem = self.basket.add(hammer)
     self.assertEqual(1, self.basket.total_items())