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_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_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_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 == []
Example #6
0
 async def show_menu(self, ctx: commands.Command):
     result = InventoryUtil.ShopMenu(ctx.guild.id)
     if len(result) < 1:
         await ctx.send('目前商品都被買光了!')
     else:
         msg = "```\n"
         msg += "{:^63}".format("===商品價目表===")
         msg += "\n"
         for products in result:
             msg += " 購買ID: {}".format(str(products.item.id).ljust(3, " "))
             msg += " 商品名稱: {}".format(products.item.name).ljust(15, " ")
             msg += " 等級限制: {}".format(
                 str(products.item.level_required).ljust(3, " "))
             msg += " 價格: {}".format(
                 str(products.item.token_required).ljust(3, " "))
             msg += " 供應數量: {}\n".format(
                 str(products.amount).ljust(3, " ")
                 if products.amount > 0 else "無限".ljust(3, " "))
         msg += "```"
         await ctx.send(msg)
 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