def test_DKPAuction_model_bid_text(self): item_name = 'Copper Disc' itemdrop = models.ItemDrop(item_name, "Jim", "timestamp") auc = models.DKPAuction(itemdrop, 'VCR', min_dkp=3) # No bids config.PRIMARY_BID_CHANNEL = 'auc' self.assertEqual( "/AUC ~[Copper Disc] (DRU, SHD) - BID IN /AUC, MIN 3 DKP. " "You MUST include the item name in your bid! Closing in {}. ". format(auc.time_remaining_text()), auc.bid_text()) # Valid bid result = auc.add(3, 'Peter') self.assertTrue(result) self.assertListEqual([('Peter', 3)], auc.highest()) # Bid exists config.PRIMARY_BID_CHANNEL = 'shout' self.assertEqual( "/SHOUT ~[Copper Disc] (DRU, SHD) - BID IN /SHOUT. " "You MUST include the item name in your bid! Currently: " "`Peter` with 3 DKP - Closing in {}! ".format( auc.time_remaining_text()), auc.bid_text()) item_name = 'Golden Jasper Earring' itemdrop = models.ItemDrop(item_name, "Jim", "timestamp") auc = models.DKPAuction(itemdrop, 'VCR', min_dkp=3) # No bids config.PRIMARY_BID_CHANNEL = 'gu' self.assertEqual( "/GU ~[Golden Jasper Earring] - BID IN /GU, MIN 3 DKP. " "You MUST include the item name in your bid! Closing in {}. ". format(auc.time_remaining_text()), auc.bid_text())
def start_auction_dkp(item: models.ItemDrop, alliance="") -> models.DKPAuction: names = (item.name() for item in config.ACTIVE_AUCTIONS.values()) if item.name in names: LOG.warning("Item %s already pending bid, not starting another.", item.name) return None auc = models.DKPAuction(item, alliance) config.PENDING_AUCTIONS.remove(item) config.ACTIVE_AUCTIONS[item.uuid] = auc LOG.info("Started DKP bid for item: %s", item) return auc
def test_handle_bid_all_matchers(self, mock_post_event, mock_store_state): item_name = 'Copper Disc' itemdrop = models.ItemDrop(item_name, "Jim", "timestamp") disc_auction = models.DKPAuction(itemdrop, 'VCR') config.ACTIVE_AUCTIONS = {itemdrop.uuid: disc_auction} # Check SAY line = ("[Sun Aug 16 22:47:31 2020] Jim says, " "'Copper Disc 10 DKP'") match = config.MATCH_BID_SAY.match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) # Check OOC line = ("[Sun Aug 16 22:47:31 2020] Jim says out of character, " "'Copper Disc 11 DKP'") match = config.MATCH_BID_OOC.match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) # Check AUC line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'Copper Disc 12 DKP'") match = config.MATCH_BID_AUC.match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) # Check SHOUT line = ("[Sun Aug 16 22:47:31 2020] Jim shouts, " "'Copper Disc 13 DKP'") match = config.MATCH_BID_SHOUT.match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) # Check GU line = ("[Sun Aug 16 22:47:31 2020] Jim tells the guild, " "'Copper Disc 14 DKP'") match = config.MATCH_BID_GU.match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) config.ACTIVE_AUCTIONS.clear()
def test_DKPAuction_model_add(self): item_name = 'Copper Disc' itemdrop = models.ItemDrop(item_name, "Jim", "timestamp") auc = models.DKPAuction(itemdrop, 'VCR', min_dkp=3) self.assertListEqual([], auc.highest()) # Bid too low result = auc.add(2, 'Peter') self.assertFalse(result) self.assertListEqual([], auc.highest()) # First bid, valid result = auc.add(10, 'Peter') self.assertTrue(result) self.assertListEqual([('Peter', 10)], auc.highest()) # Second bid, lower than first bid result = auc.add(8, 'Paul') self.assertFalse(result) self.assertListEqual([('Peter', 10)], auc.highest()) # Third bid, higher than first bid result = auc.add(12, 'Mary') self.assertTrue(result) self.assertListEqual([('Mary', 12)], auc.highest()) # Fourth bid, tied with highest bid result = auc.add(12, 'Dan') self.assertFalse(result) self.assertListEqual([('Mary', 12)], auc.highest()) # Invalid bid result = auc.add(None, 'Fred') self.assertFalse(result) # Should be JSON Encodable auc_json = json.dumps(auc, cls=utils.JSONEncoder) # Should be JSON Decodable loaded_auc = json.loads(auc_json, cls=utils.JSONDecoder) self.assertEqual(auc, loaded_auc)
def test_handle_bid(self, mock_post_event, mock_store_state): config.LAST_WHO_SNAPSHOT = { 'Jim': models.Player('Jim', None, None, 'Venerate'), 'Pim': models.Player('Pim', None, None, 'Castle'), 'Tim': models.Player('Tim', None, None, 'Kingdom'), 'Dan': models.Player('Dan', None, None, 'Dial a Daniel'), } item_name = 'Copper Disc' itemdrop = models.ItemDrop(item_name, "Jim", "timestamp") disc_auction = models.DKPAuction(itemdrop, 'VCR') config.ACTIVE_AUCTIONS = {itemdrop.uuid: disc_auction} # FILTER ON - Someone in the alliance bids on an inactive item config.RESTRICT_BIDS = True line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'Platinum Disc 10 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertListEqual([], disc_auction.highest()) self.assertEqual(1, len(config.ACTIVE_AUCTIONS)) mock_post_event.assert_not_called() # FILTER ON - Someone outside the alliance bids on an active item line = ("[Sun Aug 16 22:47:31 2020] Dan auctions, " "'Copper Disc 10 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertEqual([], disc_auction.highest()) mock_post_event.assert_not_called() # FILTER OFF - Someone in the alliance bids on an inactive item config.RESTRICT_BIDS = False line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'Platinum Disc 10 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertListEqual([], disc_auction.highest()) self.assertEqual(1, len(config.ACTIVE_AUCTIONS)) mock_post_event.assert_not_called() # FILTER ON - Someone outside the alliance bids on an active item config.RESTRICT_BIDS = True line = ("[Sun Aug 16 22:47:31 2020] Dan auctions, " "'Copper Disc 10 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertEqual([], disc_auction.highest()) mock_post_event.assert_not_called() # Someone in the alliance says random stuff with a number line = ("[Sun Aug 16 22:47:31 2020] Tim auctions, " "'I am 12 and what channel is this'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertListEqual([], disc_auction.highest()) mock_post_event.assert_not_called() # Someone in the alliance bids on two items at once line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'Copper Disc 10 DKP Platinum Disc'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertListEqual([], disc_auction.highest()) mock_post_event.assert_not_called() # Someone we haven't seen bids on an active item line = ("[Sun Aug 16 22:47:31 2020] Paul auctions, " "'Copper Disc 5 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) self.assertListEqual([('Paul', 5)], disc_auction.highest()) mock_post_event.assert_called_once_with('window', models.BidEvent(disc_auction)) mock_post_event.reset_mock() # Someone in the alliance bids on an active item line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'Copper Disc 10 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) self.assertIn(('Jim', 10), disc_auction.highest()) mock_post_event.assert_called_once_with('window', models.BidEvent(disc_auction)) mock_post_event.reset_mock() # Someone in the alliance bids on an active item with wrong case line = ("[Sun Aug 16 22:47:31 2020] Pim auctions, " "'copper DISC 11 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) self.assertIn(('Pim', 11), disc_auction.highest()) mock_post_event.assert_called_once_with('window', models.BidEvent(disc_auction)) mock_post_event.reset_mock() # Someone in the alliance bids on an active item for their 2nd main # This would trigger a bug with "2nd" being read as "2 DKP" line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'Copper Disc 2nd main 12dkp'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertTrue(result) self.assertIn(('Jim', 12), disc_auction.highest()) mock_post_event.assert_called_once_with('window', models.BidEvent(disc_auction)) mock_post_event.reset_mock() # Someone in the alliance avoids bidding using ~ line = ("[Sun Aug 16 22:47:31 2020] Jim auctions, " "'~Copper Disc 14 DKP'") match = config.MATCH_BID[1].match(line) result = message_handlers.handle_bid(match, 'window') self.assertFalse(result) self.assertListEqual([('Jim', 12)], disc_auction.highest()) mock_post_event.assert_not_called() config.ACTIVE_AUCTIONS.clear()