def test_set_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Set bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name':'bob', 'password':'******'}) # Test setting e-mail Set(bob, 'email [email protected]', 'set').run() self.assertEqual('*****@*****.**', bob.email) # Test setting title Set(bob, 'title is the best EVAR', 'set').run() self.assertEqual('is the best EVAR', bob.title) # Try to set goto_appear and goto_disappear (both should fail # since this player shouldn't have permissions) Set(bob, 'goto_appear Bob pops in from nowhere.', 'set').run() eresult = 'You don\'t have the permissions to set that.' self.assertTrue(eresult in bob.outq) bob.outq = [] Set(bob, 'goto_disappear foo', 'set').run() self.assertTrue(eresult in bob.outq) bob.permissions = bob.permissions | config.BUILDER # Try to set goto_appear and goto_disappear (both should now # succeed now that the player has adequate permissions) Set(bob, 'goto_appear Bob pops in from nowhere.', 'set').run() self.assertEqual('Bob pops in from nowhere.', bob.goto_appear) bob.outq = [] Set(bob, 'goto_disappear foo', 'set').run() self.assertEqual('foo', bob.goto_disappear)
def test_set_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Set bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name': 'bob', 'password': '******'}) # Test setting e-mail Set(bob, 'email [email protected]', 'set').run() self.assertEqual('*****@*****.**', bob.email) # Test setting title Set(bob, 'title is the best EVAR', 'set').run() self.assertEqual('is the best EVAR', bob.title) # Try to set goto_appear and goto_disappear (both should fail # since this player shouldn't have permissions) Set(bob, 'goto_appear Bob pops in from nowhere.', 'set').run() eresult = 'You don\'t have the permissions to set that.' self.assertTrue(eresult in bob.outq) bob.outq = [] Set(bob, 'goto_disappear foo', 'set').run() self.assertTrue(eresult in bob.outq) bob.permissions = bob.permissions | config.BUILDER # Try to set goto_appear and goto_disappear (both should now # succeed now that the player has adequate permissions) Set(bob, 'goto_appear Bob pops in from nowhere.', 'set').run() self.assertEqual('Bob pops in from nowhere.', bob.goto_appear) bob.outq = [] Set(bob, 'goto_disappear foo', 'set').run() self.assertEqual('foo', bob.goto_disappear)
def test_shiny_player_format(self): from shinymud.lib.sport_plugins.formatters.player_write_shiny_format import format as writeshiny from shinymud.lib.sport_plugins.formatters.player_read_shiny_format import format as readshiny from shinymud.models.player import Player #create a playa sven = Player(('foo', 'bar')) sven.playerize({'name': 'sven', 'password': '******'}) sven.permissions = 17 sven.description = "I'm pretty adorable." sven.title = 'Super Sven' sven.save() area = self._create_area() sven.item_add(area.get_item('1').load()) txt = writeshiny(sven) self.world.log.debug(txt) sven.destruct() # Sven should have been taken out of the database... row = self.world.db.select('* from player where name=?', ['sven']) self.assertFalse(row) row = self.world.db.select('* from game_item where owner=?', [sven.dbid]) self.assertFalse(row) result = readshiny(self.world, txt) self.world.log.debug(result) self.assertEqual(result, 'Character "Sven" has been successfully imported.') # Sven should now be in the database, but not online row = self.world.db.select('* from player where name=?', ['sven'])[0] self.assertTrue(row) self.assertFalse(self.world.get_player('sven')) isven = Player(('foo', 'bar')) isven.playerize(row) row = self.world.db.select('* from game_item where owner=?', [isven.dbid]) self.assertTrue(row) # Make sure that all attributes we set got imported correctly self.assertEqual(sven.password, isven.password) self.assertEqual(sven.description, isven.description) self.assertEqual(sven.name, isven.name) self.assertEqual(sven.title, isven.title) self.assertEqual(sven.permissions, isven.permissions) # Make sure that the inventory was correctly loaded self.assertEqual(len(sven.inventory), len(isven.inventory)) item = isven.inventory[0] self.world.log.debug(item.create_save_dict()) self.world.log.debug(item.item_types) self.assertFalse(sven.inventory[0] is isven.inventory[0]) self.assertEqual(item.name, 'chair') self.assertTrue(item.has_type('furniture')) self.assertEqual(item.item_types['furniture'].capacity, 5)
def test_goto_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Goto blarg_area = Area.create({'name': 'blarg'}) foo_area = Area.create({'name': 'foo'}) blarg_room = blarg_area.new_room() foo_room = foo_area.new_room() bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name': 'bob', 'password': '******'}) self.world.player_add(bob) bob.permissions = bob.permissions | config.BUILDER generic_fail = 'Type "help goto" for help with this command.' # We should fail if we only specify a room number when we aren't in # an area Goto(bob, '%s' % foo_room.id, 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(generic_fail in bob.outq) # We should fail if we try to go to a room in an area that doesn't # exist message = 'Area "food" doesn\'t exist.' Goto(bob, '1 food', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should fail if we try to go to a room that doesn't exist (in an # area that does) message = 'Room "4005" doesn\'t exist in area blarg.' Goto(bob, '4005 blarg', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should succeed in going to a room and area that exists Goto(bob, '%s %s' % (foo_room.id, foo_room.area.name), 'goto').run() self.assertEqual(bob.location, foo_room) Goto(bob, '%s %s' % (blarg_room.id, blarg_room.area.name), 'goto').run() self.assertEqual(bob.location, blarg_room) blarg_r2 = blarg_area.new_room() Goto(bob, '%s' % (blarg_r2.id), 'goto').run() self.assertEqual(bob.location, blarg_r2) # We should get a help message if there is only white space given bob.outq = [] Goto(bob, ' ', 'goto').run() fail = 'Type "help goto" for help with this command.' self.assertTrue(fail in bob.outq)
def test_goto_command(self): from shinymud.models.area import Area from shinymud.data import config from shinymud.models.player import Player from shinymud.commands.commands import Goto blarg_area = Area.create({'name':'blarg'}) foo_area = Area.create({'name':'foo'}) blarg_room = blarg_area.new_room() foo_room = foo_area.new_room() bob = Player(('bob', 'bar')) bob.mode = None bob.playerize({'name':'bob', 'password':'******'}) self.world.player_add(bob) bob.permissions = bob.permissions | config.BUILDER generic_fail = 'Type "help goto" for help with this command.' # We should fail if we only specify a room number when we aren't in # an area Goto(bob, '%s' % foo_room.id, 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(generic_fail in bob.outq) # We should fail if we try to go to a room in an area that doesn't # exist message = 'Area "food" doesn\'t exist.' Goto(bob, '1 food', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should fail if we try to go to a room that doesn't exist (in an # area that does) message = 'Room "4005" doesn\'t exist in area blarg.' Goto(bob, '4005 blarg', 'goto').run() self.assertEqual(bob.location, None) bob.world.log.debug(bob.outq) self.assertTrue(message in bob.outq) # We should succeed in going to a room and area that exists Goto(bob, '%s %s' % (foo_room.id, foo_room.area.name), 'goto').run() self.assertEqual(bob.location, foo_room) Goto(bob, '%s %s' % (blarg_room.id, blarg_room.area.name), 'goto').run() self.assertEqual(bob.location, blarg_room) blarg_r2 = blarg_area.new_room() Goto(bob, '%s' % (blarg_r2.id), 'goto').run() self.assertEqual(bob.location, blarg_r2) # We should get a help message if there is only white space given bob.outq = [] Goto(bob, ' ', 'goto').run() fail = 'Type "help goto" for help with this command.' self.assertTrue(fail in bob.outq)