Ejemplo n.º 1
0
def test_selected_files(mock_handle, test_download):
    """
    Test whether the selected files are set correctly
    """
    def mocked_set_file_prios(_):
        mocked_set_file_prios.called = True

    mocked_set_file_prios.called = False

    mocked_file = MockObject()
    mocked_file.path = 'my/path'
    mock_torrent_info = MockObject()
    mock_torrent_info.files = lambda: [mocked_file, mocked_file]
    test_download.handle.prioritize_files = mocked_set_file_prios
    test_download.handle.get_torrent_info = lambda: mock_torrent_info
    test_download.handle.rename_file = lambda *_: None

    test_download.get_share_mode = lambda: False
    test_download.tdef.get_infohash = lambda: b'a' * 20
    test_download.set_selected_files([0])
    assert mocked_set_file_prios.called

    test_download.get_share_mode = lambda: False
    mocked_set_file_prios.called = False
    assert not mocked_set_file_prios.called
Ejemplo n.º 2
0
    def test_selected_files(self):
        """
        Test whether the selected files are set correctly
        """
        def mocked_set_file_prios(_):
            mocked_set_file_prios.called = True

        mocked_set_file_prios.called = False

        mocked_file = MockObject()
        mocked_file.path = 'my/path'
        mock_torrent_info = MockObject()
        mock_torrent_info.files = lambda: [mocked_file, mocked_file]
        self.download.handle.prioritize_files = mocked_set_file_prios
        self.download.handle.get_torrent_info = lambda: mock_torrent_info
        self.download.handle.rename_file = lambda *_: None

        self.download.get_share_mode = lambda: False
        self.download.tdef.get_infohash = lambda: b'a' * 20
        self.download.set_selected_files([0])
        self.assertTrue(mocked_set_file_prios.called)

        self.download.get_share_mode = lambda: False
        mocked_set_file_prios.called = False
        self.assertFalse(mocked_set_file_prios.called)