def test_contact_not_present_on_txm(self): # Setup o_input = builtins.input builtins.input = lambda x: 'Yes' user_input = UserInput('rm [email protected]') contact_list = ContactList(nicks=['Bob']) window = Window(window_contact=[contact_list.get_contact('Bob')], type='group') group_list = GroupList(groups=[]) settings = Settings() queues = {KEY_MANAGEMENT_QUEUE: Queue(), COMMAND_PACKET_QUEUE: Queue()} # Test self.assertIsNone( remove_contact(user_input, window, contact_list, group_list, settings, queues)) self.assertEqual(queues[COMMAND_PACKET_QUEUE].qsize(), 1) command_packet, settings_ = queues[COMMAND_PACKET_QUEUE].get() self.assertIsInstance(command_packet, bytes) self.assertIsInstance(settings_, Settings) # Teardown builtins.input = o_input queues[KEY_MANAGEMENT_QUEUE].close() queues[COMMAND_PACKET_QUEUE].close()
def test_successful_removal_of_contact(self): # Setup o_input = builtins.input builtins.input = lambda x: 'Yes' user_input = UserInput('rm Alice') contact_list = ContactList(nicks=['Alice']) window = Window(window_contacts=[contact_list.get_contact('Alice')], type='contact') group_list = GroupList(groups=['testgroup']) settings = Settings() queues = {KEY_MANAGEMENT_QUEUE: Queue(), COMMAND_PACKET_QUEUE: Queue()} # Test for g in group_list: self.assertIsInstance(g, Group) self.assertTrue(g.has_member('*****@*****.**')) self.assertIsNone( remove_contact(user_input, window, contact_list, group_list, settings, queues)) self.assertEqual(queues[COMMAND_PACKET_QUEUE].qsize(), 1) km_data = queues[KEY_MANAGEMENT_QUEUE].get() self.assertEqual(km_data, ('REM', '*****@*****.**')) self.assertFalse(contact_list.has_contact('*****@*****.**')) for g in group_list: self.assertIsInstance(g, Group) self.assertFalse(g.has_member('*****@*****.**')) # Teardown builtins.input = o_input
def test_successful_removal_of_last_member_of_active_group(self): # Setup builtins.input = lambda _: 'Yes' user_input = UserInput('rm Alice') window = TxWindow( window_contacts=[self.contact_list.get_contact('Alice')], type=WIN_TYPE_GROUP, name='testgroup') group = self.group_list.get_group('testgroup') group.members = [self.contact_list.get_contact('*****@*****.**')] # Test for g in self.group_list: self.assertIsInstance(g, Group) self.assertTrue(g.has_member('*****@*****.**')) self.assertEqual(len(group), 1) self.assertIsNone( remove_contact(user_input, window, self.contact_list, self.group_list, self.settings, self.queues, self.master_key)) time.sleep(0.1) for g in self.group_list: self.assertIsInstance(g, Group) self.assertFalse(g.has_member('*****@*****.**')) self.assertFalse(self.contact_list.has_contact('*****@*****.**')) self.assertEqual(self.queues[COMMAND_PACKET_QUEUE].qsize(), 2) km_data = self.queues[KEY_MANAGEMENT_QUEUE].get() self.assertEqual(km_data, (KDB_REMOVE_ENTRY_HEADER, '*****@*****.**'))
def test_no_contact_found_on_txm(self): # Setup builtins.input = lambda _: 'Yes' user_input = UserInput('rm [email protected]') contact_list = ContactList(nicks=['Bob']) window = TxWindow(window_contact=[contact_list.get_contact('Bob')], type=WIN_TYPE_GROUP) # Test self.assertIsNone( remove_contact(user_input, window, self.contact_list, self.group_list, self.settings, self.queues, self.master_key)) time.sleep(0.1) self.assertEqual(self.queues[COMMAND_PACKET_QUEUE].qsize(), 2) command_packet, settings_ = self.queues[COMMAND_PACKET_QUEUE].get() self.assertIsInstance(command_packet, bytes) self.assertIsInstance(settings_, Settings)