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))
Esempio n. 2
0
 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)
Esempio n. 4
0
 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)
Esempio n. 5
0
 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)
Esempio n. 6
0
 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)
Esempio n. 7
0
def store_buy(request, item_type, item_id, quantity=1):
    #item_id could be a sticker.type_id or a Sticker.
    #TODO ^^^ is this true? item_id comes from JSON, so how would it be a Sticker? --alex

    try:
        quantity = int(quantity)
    except TypeError:
        raise ServiceError('Invalid parameter values.')

    if quantity == 0:
        raise ServiceError("Can't buy 0 stickers.")

    if not stickers.get(item_id).is_purchasable(request.user):
        raise ServiceError('Sticker is unpurchasable for you.')

    if item_type == 'sticker':
        try:
            remaining = economy.purchase_stickers(request.user, item_id, quantity)
        except economy.InvalidPurchase, ip:
            raise ServiceError(*ip.args)
Esempio n. 8
0
def store_buy(request, item_type, item_id, quantity=1):
    #item_id could be a sticker.type_id or a Sticker.
    #TODO ^^^ is this true? item_id comes from JSON, so how would it be a Sticker? --alex

    try:
        quantity = int(quantity)
    except TypeError:
        raise ServiceError('Invalid parameter values.')

    if quantity == 0:
        raise ServiceError("Can't buy 0 stickers.")

    if not stickers.get(item_id).is_purchasable(request.user):
        raise ServiceError('Sticker is unpurchasable for you.')

    if item_type == 'sticker':
        try:
            remaining = economy.purchase_stickers(request.user, item_id,
                                                  quantity)
        except economy.InvalidPurchase, ip:
            raise ServiceError(*ip.args)