def test_is_purchasable(self):
     user = create_rich_user()
     # Grab a purchasable sticker
     banana = stickers.get("banana")
     user.kv.stickers.add_limited_sticker(self.sticker)
     self.assertTrue(banana.cost)
     # Purchase it twice
     # @TODO: we should rafactor the api calls to be able to take
     # arguments that are not wrapped in the request payload.
     request = FakeRequest(user)
     request.POST = dict(item_type="sticker", item_id=banana.type_id)
     request.method = "POST"
     request.body = {}
     for _ in range(0, 2):
         # Buy
         store_buy(request)
         self.assertTrue(banana.is_purchasable(user))
 def test_is_purchasable(self):
     user = create_rich_user()
     # Grab a purchasable sticker
     banana = stickers.get("banana")
     user.kv.stickers.add_limited_sticker(self.sticker)
     self.assertTrue(banana.cost)
     # Purchase it twice
     # @TODO: we should rafactor the api calls to be able to take 
     # arguments that are not wrapped in the request payload.
     request = FakeRequest(user)
     request.POST = dict(item_type="sticker", item_id=banana.type_id)
     request.method = "POST"
     request.body = {}
     for _ in range(0, 2):
         # Buy
         store_buy(request)
         self.assertTrue(banana.is_purchasable(user))
    def test_is_purchasable_limited_availability(self):
        user = create_rich_user()

        # Grab a limited availability sticker
        sticker = self.sticker
        user.kv.stickers.add_limited_sticker(sticker)

        self.assertTrue(sticker.is_purchasable(user))

        # Buy it
        request = FakeRequest(user)
        request.POST = dict(item_type="sticker", item_id=sticker)
        request.method = "POST"
        request.body = {}
        assert store_buy(request)

        # is_purchasable should still return True. The logic that checks for
        # whether you bought this sticker twice happens in the api.
        self.assertTrue(sticker.is_purchasable(user))
    def test_is_purchasable_limited_availability(self):
        user = create_rich_user()

        # Grab a limited availability sticker
        sticker = self.sticker
        user.kv.stickers.add_limited_sticker(sticker)
        
        self.assertTrue(sticker.is_purchasable(user))
        
        # Buy it
        request = FakeRequest(user)
        request.POST = dict(item_type="sticker", item_id=sticker)
        request.method = "POST"
        request.body = {}
        assert store_buy(request)
        
        # is_purchasable should still return True. The logic that checks for 
        # whether you bought this sticker twice happens in the api.
        self.assertTrue(sticker.is_purchasable(user))