def test_should_receive_messages_sent_to_lobby(self): self.test_messages_should_be_sent_to_lobby_by_default() ch_c = self.c.getChannel() ch_c2 = self.c2.getChannel() self.assertEqual('hello to foo', ch_c.getMessages()[-1].text) self.assertEqual('hello to foo', ch_c2.getMessages()[-1].text) self.assertEqual(GroupView.defaultNickFromAddress(self.c2.getListenAddress()), ch_c.getMessages()[-1].nick) self.assertEqual(GroupView.defaultNickFromAddress(self.c2.getListenAddress()), ch_c2.getMessages()[-1].nick)
def test_should_be_able_to_list_channel_participants_of_nonlobby_channel(self): self._startTwoAgents() self._enterChannel(self.c, 'foo') self._enterChannel(self.c2, 'foo') for chat_instance in (self.c, self.c2): fooChannel = chat_instance.getChannel('foo') assert(GroupView.defaultNickFromAddress(chat_instance.getListenAddress()) in fooChannel.getUsers())
def test_should_be_able_to_list_channel_participants_of_lobby(self): self._startTwoAgents() # Channel should be initialized with the Chat instance to which it belongs to so that they # can communicate between each other. # lobby should be a subclass of Channel (first idea that came to mind) where its getParticipants() # that just outputs the Chat's groupview's users for chat_instance in (self.c, self.c2): lobby = chat_instance.getChannel() #changed to assert assert(GroupView.defaultNickFromAddress(chat_instance.getListenAddress()) in lobby.getUsers())
def test_chat_get_channel_with_channel_to_which_we_belong_should_work(self): self.c.start() self.c.createGroup() # because c has no nick until it joins a group time.sleep(0.1) self._enterChannel(self.c, 'foo') ch = self.c.getChannel('foo') self.assertEqual('foo', ch.getName()) self.assertEqual(1, len(ch.getUsers())) assert(GroupView.defaultNickFromAddress(self.c.getListenAddress()) in ch.getUsers())
def test_messages_sent_to_nonlobby_channel_should_reach_users_everywhere(self): # spawn 3 clients self._startThreeAgents() self._enterChannel(self.c, 'foo') self._enterChannel(self.c2, 'foo') # prepare prev_c3_count = len(self.c3.getMessages()) ch_c = self.c.getChannel('foo') ch_c2 = self.c2.getChannel('foo') # now send the message self.c2.sendMessage('hello to foo', 'foo') time.sleep(0.1) self.assertEqual(prev_c3_count + 1, len(self.c3.getMessages())) self.assertEqual('hello to foo', ch_c.getMessages()[-1].text) self.assertEqual('hello to foo', ch_c2.getMessages()[-1].text) self.assertEqual(GroupView.defaultNickFromAddress(self.c2.getListenAddress()), ch_c.getMessages()[-1].nick) self.assertEqual(GroupView.defaultNickFromAddress(self.c2.getListenAddress()), ch_c2.getMessages()[-1].nick)
def test_should_ignore_messages_from_someone_not_in_the_group(self): self.test_should_be_able_to_create_group_if_not_already_in_a_group() self.c2 = Chat((Chat.DEFAULT_LISTEN_IP, getUnusedListenPort())) # send a message from c2 to c c1msgs = len(self.c.messages) c2rcv = len(self.c2.receivedPackets()) c2nick = GroupView.defaultNickFromAddress(self.c2.getListenAddress()) net.send(Message('hi', c2nick, 'lobby'), self.c2.getListenAddress(), self.c.getListenAddress()) time.sleep(0.1) self.assertEqual(c1msgs, len(self.c.messages)) self.assertEqual(c2rcv, len(self.c2.receivedPackets()))
def test_should_notify_others_when_joining_channel(self): self.test_should_be_able_to_enter_into_a_channel() cNick = GroupView.defaultNickFromAddress(self.c.getListenAddress()) assert('foo' in self.c2.getUserInfo(cNick)['channels'])