Esempio n. 1
0
    def test_class(self):
        # Setup
        contact_list           = ContactList(nicks=['Alice', 'Bob', 'local'])
        group_list             = GroupList(groups=['testgroup'])
        packet_list            = PacketList()
        settings               = Settings()
        window_list            = WindowList(contact_list, group_list, packet_list, settings)
        window_list.active_win = window_list.get_window('*****@*****.**')

        # Test
        self.assertEqual(len(window_list), 3)

        for w in window_list:
            self.assertIsInstance(w, Window)

        self.assertIsNone(window_list.select_rx_window('*****@*****.**'))

        self.assertTrue(window_list.active_win.is_active)
        self.assertEqual(window_list.active_win, window_list.get_window('*****@*****.**'))

        self.assertTrue(window_list.has_window('*****@*****.**'))
        self.assertFalse(window_list.has_window('*****@*****.**'))

        local_win = window_list.get_local_window()
        self.assertIsInstance(local_win, Window)
        self.assertEqual(local_win.name, 'system messages')

        file_win = window_list.get_window('file_window')
        self.assertIsInstance(file_win, FileWindow)
Esempio n. 2
0
class TestWindowList(TFCTestCase):
    def setUp(self):
        self.settings = Settings()
        self.contact_list = ContactList(
            nicks=['Alice', 'Bob', 'Charlie', LOCAL_ID])
        self.group_list = GroupList(groups=['test_group', 'test_group2'])
        self.packet_list = PacketList()

        group = self.group_list.get_group('test_group')
        group.members = list(
            map(self.contact_list.get_contact, ['Alice', 'Bob', 'Charlie']))

        self.window_list = WindowList(self.settings, self.contact_list,
                                      self.group_list, self.packet_list)

    def create_window(self, uid):
        return RxWindow(uid, self.contact_list, self.group_list, self.settings,
                        self.packet_list)

    def test_active_win_is_none_if_local_key_is_not_present(self):
        # Setup
        self.contact_list.contacts = []

        # Test
        window_list = WindowList(self.settings, self.contact_list,
                                 self.group_list, self.packet_list)
        self.assertEqual(window_list.active_win, None)

    def test_active_win_is_local_win_if_local_key_is_present(self):
        # Setup
        self.contact_list.contacts = [create_contact(LOCAL_ID)]

        # Test
        self.assertEqual(self.window_list.active_win.uid, LOCAL_ID)

    def test_len_returns_number_of_windows(self):
        self.assertEqual(len(self.window_list), 7)

    def test_window_list_iterates_over_windows(self):
        for w in self.window_list:
            self.assertIsInstance(w, RxWindow)

    def test_group_windows(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g) for g in ['test_group', 'test_group2']
        ]

        # Test
        for g in self.window_list.get_group_windows():
            self.assertEqual(g.type, WIN_TYPE_GROUP)

    def test_has_window(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g) for g in ['test_group', 'test_group2']
        ]

        # Test
        self.assertTrue(self.window_list.has_window('test_group'))
        self.assertTrue(self.window_list.has_window('test_group2'))
        self.assertFalse(self.window_list.has_window('test_group3'))

    def test_remove_window(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g) for g in ['test_group', 'test_group2']
        ]

        # Test
        self.assertEqual(len(self.window_list), 2)
        self.assertIsNone(self.window_list.remove_window('test_group3'))
        self.assertEqual(len(self.window_list), 2)
        self.assertIsNone(self.window_list.remove_window('test_group2'))
        self.assertEqual(len(self.window_list), 1)

    def test_select_rx_window(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g) for g in ['test_group', 'test_group2']
        ]
        tg_win = self.window_list.windows[0]
        tg2_win = self.window_list.windows[1]
        tg_win.is_active = True
        self.window_list.active_win = tg_win

        # Test
        self.assertPrints(
            f"""{CLEAR_ENTIRE_SCREEN}{CURSOR_LEFT_UP_CORNER}
                This window for test_group2 is currently empty.                 

""", self.window_list.select_rx_window, 'test_group2')
        self.assertFalse(tg_win.is_active)
        self.assertTrue(tg2_win.is_active)

    def test_select_rx_file_window(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g)
            for g in ['test_group', 'test_group2', WIN_TYPE_FILE]
        ]
        tg_win = self.window_list.windows[0]
        tg_win.is_active = True
        self.window_list.active_win = tg_win
        self.packet_list.packets = [
            Packet(type=FILE,
                   name='testfile.txt',
                   assembly_pt_list=5 * [b'a'],
                   packets=10,
                   size="100.0KB",
                   contact=create_contact('Bob'))
        ]

        # Test
        self.assertPrints(
            f"""\

File name        Size        Sender     Complete    
────────────────────────────────────────────────────────────────────────────────
testfile.txt     100.0KB     Bob        50.00%      

{5*(CURSOR_UP_ONE_LINE+CLEAR_ENTIRE_LINE)}""",
            self.window_list.select_rx_window, WIN_TYPE_FILE)

        self.assertFalse(tg_win.is_active)
        self.assertTrue(self.window_list.get_window(WIN_TYPE_FILE).is_active)

    def test_get_local_window(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g)
            for g in ['test_group', 'test_group2', WIN_TYPE_FILE, LOCAL_ID]
        ]

        # Test
        self.assertEqual(self.window_list.get_local_window().uid, LOCAL_ID)

    def test_get_non_existing_window(self):
        # Setup
        self.window_list.windows = [
            self.create_window(g)
            for g in ['test_group', WIN_TYPE_FILE, LOCAL_ID]
        ]

        # Test existing window
        self.assertTrue(self.window_list.has_window('test_group'))
        window = self.window_list.get_window('test_group')
        self.assertEqual(window.uid, 'test_group')

        # Test non-existing window
        self.assertFalse(self.window_list.has_window('test_group2'))
        window2 = self.window_list.get_window('test_group2')
        self.assertEqual(window2.uid, 'test_group2')
        self.assertTrue(self.window_list.has_window('test_group2'))