示例#1
0
 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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
 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)
示例#5
0
    def test_chat_command(self):
        from shinymud.models.area import Area
        from shinymud.data import config
        from shinymud.models.player import Player
        from shinymud.commands.commands import Chat

        bob = Player(('bob', 'bar'))
        alice = Player(('alice', 'bar'))
        sam = Player(('sam', 'bar'))
        bob.mode = None
        bob.playerize({'name':'bob', 'password':'******'})
        bob.outq = []
        sam.mode = None
        sam.playerize({'name':'sam', 'password':'******'})
        sam.outq = []
        self.world.player_add(bob)
        self.world.player_add(sam)
        self.world.player_add(alice)
        
        Chat(bob, 'lol, hey guys!', 'chat').run()
        chat = config.chat_color + 'Bob chats, "lol, hey guys!"' + config.clear_fcolor
        self.assertTrue(chat in sam.outq)
        self.assertTrue(chat in bob.outq)
        self.assertFalse(chat in alice.outq)
        
        sam.channels['chat'] = False
        print sam.channels
        print bob.channels
        sam.outq = []
        bob.outq = []
        alice.outq = []
        
        Chat(bob, 'lol, hey guys!', 'chat').run()
        print sam.channels
        print sam.outq
        print bob.channels
        print bob.outq
        self.assertFalse(chat in sam.outq)
        self.assertTrue(chat in bob.outq)
        self.assertFalse(chat in alice.outq)
示例#6
0
    def test_chat_command(self):
        from shinymud.models.area import Area
        from shinymud.data import config
        from shinymud.models.player import Player
        from shinymud.commands.commands import Chat

        bob = Player(('bob', 'bar'))
        alice = Player(('alice', 'bar'))
        sam = Player(('sam', 'bar'))
        bob.mode = None
        bob.playerize({'name': 'bob', 'password': '******'})
        bob.outq = []
        sam.mode = None
        sam.playerize({'name': 'sam', 'password': '******'})
        sam.outq = []
        self.world.player_add(bob)
        self.world.player_add(sam)
        self.world.player_add(alice)

        Chat(bob, 'lol, hey guys!', 'chat').run()
        chat = config.chat_color + 'Bob chats, "lol, hey guys!"' + config.clear_fcolor
        self.assertTrue(chat in sam.outq)
        self.assertTrue(chat in bob.outq)
        self.assertFalse(chat in alice.outq)

        sam.channels['chat'] = False
        print sam.channels
        print bob.channels
        sam.outq = []
        bob.outq = []
        alice.outq = []

        Chat(bob, 'lol, hey guys!', 'chat').run()
        print sam.channels
        print sam.outq
        print bob.channels
        print bob.outq
        self.assertFalse(chat in sam.outq)
        self.assertTrue(chat in bob.outq)
        self.assertFalse(chat in alice.outq)
示例#7
0
 def test_tell_players(self):
     from shinymud.models.player import Player
     from shinymud.modes.build_mode import BuildMode
     from shinymud.modes.init_mode import InitMode
     from shinymud.data.config import wecho_color, clear_fcolor
     from shinymud.lib.connection_handlers.shiny_connections import ShinyConnection
     
     bob = Player('foo')
     bob.name = 'bob'
     alice = Player('foo')
     alice.name = 'alice'
     self.world.player_add(bob)
     self.world.player_add(alice)
     
     bob.mode = None
     bob.outq = []
     alice.mode = None
     alice.outq = []
     
     self.world.tell_players('hello world!')
     echo = wecho_color + 'hello world!' + clear_fcolor
     self.assertTrue(echo in bob.outq)
     self.assertTrue(echo in alice.outq)
     
     bob.mode = InitMode(bob)
     bob.outq = []
     alice.outq = []
     
     self.world.tell_players('hello all!')
     echo = wecho_color + 'hello all!' + clear_fcolor
     self.assertTrue(echo not in bob.outq)
     self.assertTrue(echo in alice.outq)
     
     bob.mode = BuildMode(bob)
     bob.outq = []
     alice.outq = []
     
     self.world.tell_players('hello!', ['alice'])
     echo = wecho_color + 'hello!' + clear_fcolor
     self.assertTrue(echo in bob.outq)
     self.assertTrue(echo not in alice.outq)