def test_buyShopitem_failed_noProduct(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=100)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     ItemUtil.createItem(guild_id=1,
                         item_name="hey",
                         item_type=ItemType.STATUS,
                         buff_type=BuffType.DEFENCE,
                         buff_value=10,
                         buff_round=3,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     InventoryUtil.addItemToShop(guild_id=1,
                                 item_name="hey",
                                 amount=10,
                                 hidden=True)
     result = InventoryUtil.buyShopitem(guild_id=1,
                                        user_id=123,
                                        item_name="he",
                                        count=2)
     assert result == ErrorCode.CannotFindProduct
     result == InventoryUtil.buyShopitem(guild_id=1,
                                         user_id=123,
                                         item_name="hey",
                                         count=2)
     assert result == ErrorCode.CannotFindProduct
    def test_listHiddenitem_success(self):
        result = InventoryUtil.listHiddenShopItem(guild_id=1)
        assert len(result) == 0

        ItemUtil.createItem(guild_id=1,
                            item_name="hello",
                            item_type=ItemType.ATTACK,
                            buff_type=BuffType.ATTACK,
                            buff_value=-1,
                            buff_round=2,
                            level_required=0,
                            price=1)
        ItemUtil.createItem(guild_id=1,
                            item_name="hey",
                            item_type=ItemType.STATUS,
                            buff_type=BuffType.DEFENCE,
                            buff_value=10,
                            buff_round=3,
                            level_required=0,
                            price=1)
        InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
        InventoryUtil.addItemToShop(guild_id=1, item_name="hey", amount=10)
        InventoryUtil.changeShopitemHiddenStatus(guild_id=1,
                                                 item_name="hello",
                                                 hidden=True)
        result = InventoryUtil.listHiddenShopItem(guild_id=1)
        assert len(result) == 1

        # items
        InventoryUtil.changeShopitemHiddenStatus(guild_id=1,
                                                 item_name="hey",
                                                 hidden=True)
        result = InventoryUtil.listHiddenShopItem(guild_id=1)
        assert len(result) == 2
 def test_changeSupplyAmount_failed(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     ItemUtil.createItem(guild_id=1,
                         item_name="hey",
                         item_type=ItemType.STATUS,
                         buff_type=BuffType.DEFENCE,
                         buff_value=10,
                         buff_round=3,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     # item cannot find
     result1 = InventoryUtil.changeSupplyAmount(guild_id=1,
                                                item_name="he",
                                                newAmount=-1)
     assert result1 == -1
     # shopitem cannot find
     result2 = InventoryUtil.changeSupplyAmount(guild_id=1,
                                                item_name="hey",
                                                newAmount=-1)
     assert result2 == -2
 def test_addItemTOShop_failed_unlimitedSupply(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=-1)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     result = InventoryUtil.ShopMenu(guild_id=1)
     assert result[0].amount == -1
 def test_addItemTOShop_success_addAmount(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     result = InventoryUtil.ShopMenu(guild_id=1)
     assert result[0].amount == 20 and len(result) == 1
 def test_checkShopitemStatus_success(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     result = InventoryUtil.checkShopitemStatus(guild_id=1,
                                                item_name="hello")
     assert result.hidden == False
 def test_changeShopitemHiddenStatus_failed_noitem(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     result = InventoryUtil.changeShopitemHiddenStatus(guild_id=1,
                                                       item_name="he",
                                                       hidden=True)
     assert result == -1
 def test_addItemTOShop_failed_limitedToUnlimited(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2)
     shopitem = InventoryUtil.addItemToShop(guild_id=1,
                                            item_name="hello",
                                            amount=10)
     result = InventoryUtil.addItemToShop(guild_id=1,
                                          item_name="hello",
                                          amount=-1)
     assert result == -3 and shopitem.amount == 10
 def test_addItemTOShop_failed_noitem(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2)
     ItemUtil.createItem(guild_id=1,
                         item_name="hey",
                         item_type=ItemType.STATUS,
                         buff_type=BuffType.DEFENCE,
                         buff_value=10,
                         buff_round=3)
     InventoryUtil.addItemToShop(guild_id=1, item_name="he", amount=10)
     result = InventoryUtil.ShopMenu(guild_id=1)
     assert result == []
 def test_findShopItem_failed(self):
     item1 = ItemUtil.createItem(guild_id=1,
                                 item_name="hello",
                                 item_type=ItemType.ATTACK,
                                 buff_type=BuffType.ATTACK,
                                 buff_value=-1,
                                 buff_round=2)
     ItemUtil.createItem(guild_id=1,
                         item_name="hey",
                         item_type=ItemType.STATUS,
                         buff_type=BuffType.DEFENCE,
                         buff_value=10,
                         buff_round=3)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hey", amount=10)
     result = InventoryUtil.findShopItem(guild_id=1, item=item1)
     assert result == None
 def test_buyShopitem_failed_notEnoughSupply(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=100)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=1)
     result = InventoryUtil.buyShopitem(guild_id=1,
                                        user_id=123,
                                        item_name="hello",
                                        count=2)
     assert result == ErrorCode.SupplyDoesNotEnough
 def test_buyShopitem_success_shopItemchangeHidden(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=500)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=1)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     InventoryUtil.buyShopitem(guild_id=1,
                               user_id=123,
                               item_name="hello",
                               count=10)
     InventoryUtil.checkZeroAmount(guild_id=1)
     result = InventoryUtil.ShopMenu(guild_id=1)
     assert len(result) == 0 and result == []
 def test_deleteShopItems(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2)
     ItemUtil.createItem(guild_id=1,
                         item_name="hey",
                         item_type=ItemType.STATUS,
                         buff_type=BuffType.DEFENCE,
                         buff_value=10,
                         buff_round=3)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hey", amount=100)
     list = InventoryUtil.ShopMenu(guild_id=1)
     assert len(list) == 2
     InventoryUtil.deleteShopItems(guild_id=1)
     list = InventoryUtil.ShopMenu(guild_id=1)
     assert len(list) == 0
 def test_changeShopitemHiddenStatus_success(self):
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hello", amount=10)
     result = InventoryUtil.changeShopitemHiddenStatus(guild_id=1,
                                                       item_name="hello",
                                                       hidden=True)
     assert result.hidden == True
     result2 = InventoryUtil.ShopMenu(guild_id=1)
     assert len(result2) == 0
     result3 = InventoryUtil.changeShopitemHiddenStatus(guild_id=1,
                                                        item_name="hello",
                                                        hidden=False)
     assert result3.hidden == False
 def test_buyShopitem_success(self):
     MemberUtil.add_member(member_id=123)
     MemberUtil.add_token(member_id=123, amount=100)
     ItemUtil.createItem(guild_id=1,
                         item_name="hello",
                         item_type=ItemType.ATTACK,
                         buff_type=BuffType.ATTACK,
                         buff_value=-1,
                         buff_round=2,
                         level_required=0,
                         price=10)
     shopItem1 = InventoryUtil.addItemToShop(guild_id=1,
                                             item_name="hello",
                                             amount=10)
     InventoryUtil.addItemToShop(guild_id=1, item_name="hey", amount=10)
     InventoryUtil.buyShopitem(guild_id=1,
                               user_id=123,
                               item_name="hello",
                               count=2)
     itemList = InventoryUtil.getAllItemsBelongToUser(guild_id=1,
                                                      user_id=123)
     assert itemList[0].user_id == 123 and itemList[0].item == shopItem1.item
    def test_changeSupplyAmount_success_limitedToUnlimited(self):
        ItemUtil.createItem(guild_id=1,
                            item_name="hello",
                            item_type=ItemType.ATTACK,
                            buff_type=BuffType.ATTACK,
                            buff_value=-1,
                            buff_round=2,
                            level_required=0,
                            price=10)
        shopItem1 = InventoryUtil.addItemToShop(guild_id=1,
                                                item_name="hello",
                                                amount=10)
        assert shopItem1.amount == 10

        shopItem2 = InventoryUtil.changeSupplyAmount(guild_id=1,
                                                     item_name="hello",
                                                     newAmount=-1)
        assert shopItem2.amount == -1
示例#17
0
 async def add_item(self, ctx: commands.Command, item_count: int,
                    item_name: str):
     if item_count == 0:
         await ctx.send(f"新增數量為0?那你新增幹嘛?浪費我的時間")
     elif item_count < -1:
         await ctx.send(f"新增不能為負數,請重新輸入!")
     else:
         result = InventoryUtil.addItemToShop(ctx.guild.id, item_name,
                                              item_count)
         if result == -1:
             await ctx.send(f"{item_name}上架失敗!請確認商品名字是否正確!")
         elif result == -2:
             await ctx.send(f"{item_name}上架失敗!該物品目前無限量供應!")
         elif result == -3:
             await ctx.send(
                 f"{item_name}目前限量存在,若需更改為無限量供應,請使用!shop change指令")
         else:
             if result.amount != item_count:
                 await ctx.send(
                     f"{item_name}已存在{result.amount - item_count}個,已更新提供數量至{result.amount}個!"
                 )
             else:
                 await ctx.send(f"{item_count}個{item_name} 商品上架成功!")