Пример #1
0
class TestAvatarHandler:

    def setUp(self):
        if 'bob' in NamedObject._name_registry:
            del NamedObject._name_registry['bob']
        self.telnet = MockTelnet()
        self.avatar = self.telnet.avatar = \
                      Player("bob", "", set(),
                             grailmud.instance.startroom, '')
        self.ah = AvatarHandler(self.telnet, self.avatar)

    def test_initialisation_delegate_adding(self):
        assert self.ah.connection_state in self.avatar.delegates

    def test_initialisation_room_adding(self):
        assert self.avatar in grailmud.instance.startroom

    def test_initialisation_callback_setting(self):
        assert self.telnet.callback == self.ah.handle_line

    def test_handle_line_correct(self):
        called = []
        self.avatar.receivedLine = (lambda line, info: 
                                            called.append(('rl', line, info)))
        self.ah.handle_line('foo')
        assert called == [('rl', 'foo', LineInfo(instigator = self.avatar))]

    def test_handle_line_removing_bad_characters(self):
        lines = []
        self.avatar.receivedLine = lambda *a: lines.append(a)
        self.ah.handle_line("foo\xff")
        assert lines == [('foo', LineInfo(instigator = self.avatar))]
Пример #2
0
class TestAvatarHandler:
    def setUp(self):
        if 'bob' in NamedObject._name_registry:
            del NamedObject._name_registry['bob']
        self.telnet = MockTelnet()
        self.avatar = self.telnet.avatar = \
                      Player("bob", "", set(),
                             grailmud.instance.startroom, '')
        self.ah = AvatarHandler(self.telnet, self.avatar)

    def test_initialisation_delegate_adding(self):
        assert self.ah.connection_state in self.avatar.delegates

    def test_initialisation_room_adding(self):
        assert self.avatar in grailmud.instance.startroom

    def test_initialisation_callback_setting(self):
        assert self.telnet.callback == self.ah.handle_line

    def test_handle_line_correct(self):
        called = []
        self.avatar.receivedLine = (lambda line, info: called.append(
            ('rl', line, info)))
        self.ah.handle_line('foo')
        assert called == [('rl', 'foo', LineInfo(instigator=self.avatar))]

    def test_handle_line_removing_bad_characters(self):
        lines = []
        self.avatar.receivedLine = lambda *a: lines.append(a)
        self.ah.handle_line("foo\xff")
        assert lines == [('foo', LineInfo(instigator=self.avatar))]
Пример #3
0
 def setUp(self):
     if 'bob' in NamedObject._name_registry:
         del NamedObject._name_registry['bob']
     self.telnet = MockTelnet()
     self.avatar = self.telnet.avatar = \
                   Player("bob", "", set(),
                          grailmud.instance.startroom, '')
     self.ah = AvatarHandler(self.telnet, self.avatar)
Пример #4
0
 def setUp(self):
     if 'bob' in NamedObject._name_registry:
         del NamedObject._name_registry['bob']
     self.telnet = MockTelnet()
     self.avatar = self.telnet.avatar = \
                   Player("bob", "", set(),
                          grailmud.instance.startroom, '')
     self.ah = AvatarHandler(self.telnet, self.avatar)
Пример #5
0
def test_AvatarHandler_initialisation_calls_login():
    def fake_login(actor):
        actor.login_called = True
        login(actor)

    from grailmud.actiondefs.login import login
    from grailmud import telnet
    telnet.login = fake_login

    mocktelnet = MockTelnet()
    avatar = mocktelnet.avatar = Player("michael", "", set(),
                                        grailmud.instance.startroom, '')
    ah = AvatarHandler(mocktelnet, avatar)

    assert avatar.login_called