def test_exit(self): with locks.authority_of(locks.SYSTEM): owner = db.Object("owner") db.store(owner) with locks.authority_of(owner): source = db.Room("Source") dest = db.Room("Dest") db.store(source) db.store(dest) player = db.Object("Player", location=source) player.send = mock.MagicMock() db.store(player) exit = db.Exit("Exit", source, dest) exit.go_message = ("You, {player}, go from {source} to " "{destination} via {exit}.") db.store(exit) sourceBystander = db.Object("source bystander", location=source) sourceBystander.send = mock.MagicMock() db.store(sourceBystander) destBystander = db.Object("dest bystander", location=dest) destBystander.send = mock.MagicMock() db.store(destBystander) self.assertIs(player.location, source) exit.go(player) self.assertIs(player.location, dest) self.assertEqual(sourceBystander.send.call_count, 1) self.assertEqual(destBystander.send.call_count, 1) sourceBystander.send.assert_called_once_with( "Player leaves through Exit.") destBystander.send.assert_called_once_with("Player arrives.") player.send.assert_called_with("You, Player, go from Source to " "Dest via Exit.")
def test_exit_nospace(self): with locks.authority_of(locks.SYSTEM): self.foyer = db.Room("foyer") self.zzzfoo = db.Exit("zzzfoo", self.lobby, self.foyer) db.store(self.foyer) db.store(self.zzzfoo) self.assert_response("zzzfoo", "Spaaaaaaaaaaaaaace. (foo).")
def test_destroy_emit_elsewhere(self): with locks.authority_of(self.player): new_room = db.Room("a room") db.store(new_room) self.player.send_line("destroy #{}".format(new_room.uid)) self.assertNotEqual(self.neighbor.last_response(), "Player destroys a room.")
def test_ambiguous_exit(self): with locks.authority_of(locks.SYSTEM): self.foyer = db.Room("foyer") self.exit_ju = db.Exit("jump", self.lobby, self.foyer) self.exit_jo = db.Exit("joust", self.lobby, self.foyer) for obj in self.foyer, self.exit_ju, self.exit_jo: db.store(obj) self.assert_response("j", "Which exit do you mean? (joust, jump)")
def test_exit_permissions(self): with locks.authority_of(locks.SYSTEM): self.foyer = db.Room("foyer") self.exit = db.Exit("exit", self.lobby, self.foyer) self.exit.locks.go = locks.Fail() db.store(self.foyer) db.store(self.exit) self.assert_response("exit", "You can't go through exit.")
def setUp(self): self.patch(db, "_objects", {}) self.patch(db, "_nextUid", 0) with locks.authority_of(locks.SYSTEM): self.lobby = db.Room("lobby") db.store(self.lobby) self.player = self.new_player("Player") self.neighbor = self.new_player("PlayersNeighbor")
def test_exit_invocation(self): with locks.authority_of(locks.SYSTEM): self.foyer = db.Room("foyer") db.store(self.foyer) self.exit = db.Exit("exit", self.lobby, self.foyer) db.store(self.exit) self.assertEqual(self.player.location, self.lobby) self.player.send_line("exit") self.assertEqual(self.player.location, self.foyer)
def finish(room_name, to_exit_name, from_exit_name): room = db.Room(room_name) db.store(room) if to_exit_name != "": exit_to = db.Exit(to_exit_name, player.location, room) db.store(exit_to) if from_exit_name != "": exit_from = db.Exit(from_exit_name, room, player.location) db.store(exit_from) player.send("Dug room #{}, {}.".format(room.uid, room.name))
def test_open(self): with locks.authority_of(self.player): destination = db.Room("destination") db.store(destination) self.assert_response("open north to #{}".format(destination.uid), "Opened north to destination.") exit = db.get(destination.uid + 1) self.assertTrue(isinstance(exit, db.Exit)) self.assertIdentical(exit.location, self.lobby) self.assertIdentical(exit.destination, destination)
def test_contents_string(self): with locks.authority_of(locks.SYSTEM): room = db.Room("room") self.patch(db, '_objects', {0: room}) player = db.Player("player", "password") hat = equipment.Equipment("hat") db.store(player) db.store(hat) # not room because we already patched it in for location in [room, player]: with locks.authority_of(locks.SYSTEM): hat.equipped = False hat.location = location self.assertIn("hat", location.contents_string()) self.assertNotIn("hat", location.equipment_string()) with locks.authority_of(locks.SYSTEM): hat.equip() self.assertTrue(hat.equipped) self.assertNotIn("hat", location.contents_string()) self.assertIn("hat", location.equipment_string())