class TestSellInRoomWithMultipleActors(IFPTestCase): def setUp(self): super().setUp() self.sale_item = Thing(self.game, "bulb") self.actor1 = Actor(self.game, "dmitri") self.actor2 = Actor(self.game, "kate") self.currency = Thing(self.game, "penny") self.me.addThing(self.sale_item) self.actor1.addWillBuy(self.sale_item, self.currency, 1, 1) self.start_room.addThing(self.actor1) self.start_room.addThing(self.actor2) def test_sell(self): self.game.turnMain(f"sell {self.sale_item.verbose_name}") msg = self.app.print_stack.pop() BASE_DISAMBIG_MSG = "Would you like to sell it to" self.assertIn( BASE_DISAMBIG_MSG, msg, "Unexpected message after attempting to sell to ambiguous Actor", ) self.assertItemIn(self.sale_item, self.me.contains, "Attempted to sell to ambiguous Actor.") def test_sell_with_lastTurn_dobj_actor(self): self.game.parser.command.dobj = GrammarObject(target=self.actor1) self.game.turnMain(f"sell {self.sale_item.verbose_name}") msg = self.app.print_stack.pop() expected = ( f"(Received: {self.actor1.will_buy[self.sale_item.ix].price} " f"{self.currency.verbose_name}) ") self.assertEqual( msg, expected, "Unexpected msg after attempting to sell from ambigous Actor") self.assertItemExactlyOnceIn( self.currency, self.me.contains, "Attempted to sell item. Recieved success message. Expected 1 currency. ", ) self.assertItemNotIn( self.sale_item, self.me.contains, "Attempted to buy item. Received success message. Expected no sale_item " "in inv.", ) def test_sell_with_lastTurn_iobj_actor(self): self.game.parser.command.iobj = GrammarObject(target=self.actor1) self.assertTrue(self.game.parser.command.iobj.target) self.game.turnMain(f"sell {self.sale_item.verbose_name}") msg = self.app.print_stack.pop() expected = ( f"(Received: {self.actor1.will_buy[self.sale_item.ix].price} " f"{self.currency.verbose_name}) ") self.assertEqual( msg, expected, "Unexpected msg after attempting to sell from ambigous Actor") self.assertItemExactlyOnceIn( self.currency, self.me.contains, "Attempted to sell item. Recieved success message. Expected 1 currency. ", ) self.assertItemNotIn( self.sale_item, self.me.contains, "Attempted to buy item. Received success message. Expected no sale_item " "in inv.", )
class TestSell(IFPTestCase): def setUp(self): super().setUp() self.sale_item = Thing(self.game, "widget") self.sale_item.makeKnown(self.me) self.actor = Actor(self.game, "dmitri") self.currency = Thing(self.game, "penny") self.me.addThing(self.sale_item) self.me.addThing(self.sale_item.copyThing()) self.actor.addWillBuy(self.sale_item, self.currency, 1, 1) self.start_room.addThing(self.actor) self.BASE_DOES_NOT_WANT_MORE_MSG = "will not buy any more" def test_sell(self): self.assertItemIn( self.sale_item, self.me.contains, "This test needs widgets in the inventory. ", ) self.assertEqual(len(self.me.contains[self.sale_item.ix]), 2) self.game.turnMain(f"sell {self.sale_item.verbose_name}") msg = self.app.print_stack.pop() expected = ( f"(Received: {self.actor.will_buy[self.sale_item.ix].price} " f"{self.currency.verbose_name}) ") self.assertEqual(msg, expected, "Unexpected msg after attempting to sell item") self.assertItemExactlyOnceIn( self.currency, self.me.contains, "Attempted to sell item. Received success message. ", ) SellVerb()._runVerbFuncAndEvents(self.game, self.sale_item) msg = self.app.print_stack.pop() self.assertIn( self.BASE_DOES_NOT_WANT_MORE_MSG, msg, "Tried to sell item to actor who should not want any more. Received " "unexpected msg", ) self.assertItemExactlyOnceIn( self.currency, self.me.contains, "Attempted to buy out of stock item. Number in inventory should not have " "changed. ", ) def test_sell_to(self): self.assertItemIn( self.sale_item, self.me.contains, "This test needs widgets in the inventory. ", ) self.assertEqual(len(self.me.contains[self.sale_item.ix]), 2) self.game.turnMain( f"sell {self.sale_item.verbose_name} to {self.actor.verbose_name}") msg = self.app.print_stack.pop() expected = ( f"(Received: {self.actor.will_buy[self.sale_item.ix].price} " f"{self.currency.verbose_name}) ") self.assertEqual(msg, expected, "Unexpected msg after attempting to sell item") self.assertItemExactlyOnceIn( self.currency, self.me.contains, "Attempted to sell item. Received success message. ", ) SellToVerb()._runVerbFuncAndEvents(self.game, self.sale_item, self.actor) msg = self.app.print_stack.pop() self.assertIn( self.BASE_DOES_NOT_WANT_MORE_MSG, msg, "Tried to sell item to actor who should not want any more. Received " "unexpected msg", ) self.assertItemExactlyOnceIn( self.currency, self.me.contains, "Attempted to buy out of stock item. Number in inventory should not have " "changed. ", )