def test_cant_purchase_limited_availability_multiple_times(self): # Grab a limited availability sticker sticker = self.sticker previous_inventory = sticker.remaining # Call stickers.add_sticker so that we can use the sticker by id in api calls. stickers.add_sticker(sticker) user = tests_helpers.create_rich_user() previous_wealth = user.kv.stickers.currency.get() # Give the user this sticker. # Give them zero for now. user.kv.stickers.add_limited_sticker(sticker) # Try to purchase. Should allow them result = self.api_post('/api/store/buy', { 'item_type': 'sticker', 'item_id': sticker.type_id }, user=user) # Should not be able to buy it a second time. result = self.api_post('/api/store/buy', { 'item_type': 'sticker', 'item_id': sticker.type_id }, user=user) assert result.get("success") == False assert sticker.remaining == previous_inventory - 1
def test_purchase_sticker_limited_inventory(self): user = create_rich_user() user.kv.stickers.add_limited_sticker(self.sticker) # Purchase economy.purchase_stickers(user, self.sticker.type_id, 1) # Should not be able to buy again self.assertRaises(InvalidPurchase, lambda: economy.purchase_stickers(user, self.sticker.type_id, 1))
def test_purchase_sticker_limited_inventory(self): user = create_rich_user() user.kv.stickers.add_limited_sticker(self.sticker) # Purchase economy.purchase_stickers(user, self.sticker.type_id, 1) # Should not be able to buy again self.assertRaises( InvalidPurchase, lambda: economy.purchase_stickers(user, self.sticker.type_id, 1))
def test_purchase_sticker_unlimited_inventory(self): sticker = stickers.get("banana") assert not sticker.is_limited_inventory() user = create_rich_user() user.kv.stickers.add_limited_sticker(sticker) # Purchase economy.purchase_stickers(user, sticker.type_id, 1) # SHOULD be able to buy again for i in range(0, 10): economy.purchase_stickers(user, sticker.type_id, 1)
def test_purchase_limited_availability(self): user = tests_helpers.create_rich_user() previous_wealth = user.kv.stickers.currency.get() sticker = self.sticker # Give the user this sticker. # Give them zero for now. user.kv.stickers.add_limited_sticker(sticker) # Try to purchase. Should allow them result = self.api_post('/api/store/buy', {'item_type': 'sticker', 'item_id': sticker.type_id}, user=user) assert result print result new_wealth = result.get("new_balance") assert new_wealth == previous_wealth - sticker.cost
def _make_stickers(self, sticks=['smiley', 'banana', 'frowny', 'frowny'], top='banana', per=2): self.top_id = stickers.get(top).type_id self.stickers = map(stickers.get, sticks) self.cmt = self.post_comment(reply_content=create_content().id) from canvas import economy for sticker in self.stickers: for _ in xrange(per): user = create_rich_user() if sticker.cost: user.kv.stickers.add_limited_sticker(sticker) economy.purchase_stickers(user, sticker.type_id, 1) #user.redis.user_kv.hset('sticker:%s:count' % STORE_ITEM, 1) self.api_post('/api/sticker/comment', { 'type_id': sticker.type_id, 'comment_id': self.cmt.id, }, user=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_purchase_limited_availability(self): user = tests_helpers.create_rich_user() previous_wealth = user.kv.stickers.currency.get() sticker = self.sticker # Give the user this sticker. # Give them zero for now. user.kv.stickers.add_limited_sticker(sticker) # Try to purchase. Should allow them result = self.api_post('/api/store/buy', { 'item_type': 'sticker', 'item_id': sticker.type_id }, user=user) assert result print result new_wealth = result.get("new_balance") assert new_wealth == previous_wealth - sticker.cost
def test_cant_purchase_limited_availability_multiple_times(self): # Grab a limited availability sticker sticker = self.sticker previous_inventory = sticker.remaining # Call stickers.add_sticker so that we can use the sticker by id in api calls. stickers.add_sticker(sticker) user = tests_helpers.create_rich_user() previous_wealth = user.kv.stickers.currency.get() # Give the user this sticker. # Give them zero for now. user.kv.stickers.add_limited_sticker(sticker) # Try to purchase. Should allow them result = self.api_post('/api/store/buy', {'item_type': 'sticker', 'item_id': sticker.type_id}, user=user) # Should not be able to buy it a second time. result = self.api_post('/api/store/buy', {'item_type': 'sticker', 'item_id': sticker.type_id}, user=user) assert result.get("success") == False assert sticker.remaining == previous_inventory - 1