当前位置: 首页>>代码示例>>Python>>正文


Python Item.addBid方法代码示例

本文整理汇总了Python中Item.addBid方法的典型用法代码示例。如果您正苦于以下问题:Python Item.addBid方法的具体用法?Python Item.addBid怎么用?Python Item.addBid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Item的用法示例。


在下文中一共展示了Item.addBid方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestAuction

# 需要导入模块: import Item [as 别名]
# 或者: from Item import addBid [as 别名]
class TestAuction(unittest.TestCase):

    def setUp(self):
        self.testitem1 = Item("Car", 1000)
        self.testitem2 = Item("Boat", 10000)
        self.testitem3 = Item("Game", 100)
        self.testbidder1 = Bidder("John Doe")
        self.testbidder2 = Bidder("Jane Doe")

    # Test to check if when we add a bid, the bid stored in the item matches the added bid
    def test_add_bid_and_check_bid_methods(self):
        self.testitem1.addBid(1001, self.testbidder1)                    # Add bid by John to Car
        self.assertEqual(self.testitem1.getCurrentBid(), 1001)           # Check if the bid added matches amount stored

    # Test if adding a bidder with an argument creates that bidder object and we can access the bidder name
    def test_add_bidder(self):
        testbidder = Bidder("John Doe")                                   # Create bidder object
        self.assertEqual(testbidder.bidderName, "JOHN DOE")               # Check if there is a bidder with name

    # Check if the getItemsBidOn method retrieves the dictionary of items bid for
    def test_check_user_bid_hist_call(self):
        self.testitem1.addBid(1001, self.testbidder2)                     # Add bid by Jane to Car
        self.testitem2.addBid(10001, self.testbidder2)                    # Add bid by Jane to Boat
        bidhistdict = self.testbidder2.getItemsBidOn()                    # Make a dictionary using the method
        self.assertEqual(bidhistdict,self.testbidder2.itemsBidForDict)    # Check if it is the same as the items bid on

    # Check if we can get all the items for which a user has bid on
    def test_check_user_bid_hist(self):
        bidhistdict = self.testbidder1.getItemsBidOn()
        self.testitem2.addBid(10001, self.testbidder1)                     # Add a bid by John for Boat
        self.assertTrue("CAR" in bidhistdict and "BOAT" in self.testbidder1.getItemsBidOn())

    # Check if a bid is correctly stored in a the items bid history list
    def test_check_item_bid_hist(self):
        self.testitem1.addBid(1001.50, self.testbidder2)
        self.assertIn(('JANE DOE',1001.50),self.testitem1.bidList)

    # Check if item can be set as sold and we can check that status
    def test_check_item_set_as_sold(self):
        self.testitem1.changeStatus()                                       # Set as sold
        self.assertTrue(self.testitem1.soldStatus)                          # Check status

    # Test that if a string is added as a bid, the bid will not be registered
    def test_bid_error(self):
        self.testitem2.addBid("100000gbp",self.testbidder1)                 # Add bid with string as bid amount
        self.assertFalse(self.testitem2.bidstatus)                          # Check if bid has been made

    # Test that we can retrieve the winning bid of an item marked as sold
    def test_get_winning_bid(self):
        self.testitem2.addBid(99999, self.testbidder1)                      # Add a bid by John for Boat
        self.testitem2.changeStatus()                                       # Set it as sold
        self.assertEqual(self.testitem2.getwinningbid(),99999)              # Check if winning bid is equal to Johns bid

    # Test that we can retrieve the winning bidder of an item marked as sold
    def test_get_winning_bidder(self):
        self.testitem3.addBid(99999, self.testbidder1)
        self.testitem3.changeStatus()                                       # Set as sold
        self.assertEqual(self.testitem3.winner,"JOHN DOE")                  # Check if winner stored in item is right
开发者ID:DavidSweetman,项目名称:auction,代码行数:60,代码来源:AuctionUnitTest.py


注:本文中的Item.addBid方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。