Exemplo n.º 1
0
    async def test_specifying_torrent(self):
        from stig.commands.cli import RenameCmd
        self.mock_select_torrents.return_value = 'mock filter'
        self.mock_srvapi.torrent.torrents.return_value = Response(
            success=True,
            torrents=(MockTorrent(id=1234, name='Some Torrent'),))

        info_cb, err_cb = MagicMock(), MagicMock()
        process = RenameCmd(['id=1234', 'Renamed Torrent'], info_handler=info_cb, error_handler=err_cb, loop=self.loop)
        await process.wait_async()
        self.assertEqual(process.success, True)
        info_cb.assert_not_called()
        err_cb.assert_not_called()

        self.mock_get_relative_path_from_focused.assert_not_called()
        self.mock_select_torrents.assert_called_once_with('id=1234', allow_no_filter=False, discover_torrent=True)
        self.mock_srvapi.torrent.torrents.assert_called_once_with('mock filter', keys=('id',))
        self.mock_srvapi.torrent.rename.assert_called_once_with(1234, path=None, new_name='Renamed Torrent')
Exemplo n.º 2
0
    async def test_CLI_renaming_files_of_multiple_torrents_disabled_succeeds(self):
        from stig.commands.cli import RenameCmd
        self.mock_select_torrents.return_value = 'mock filter'
        self.mock_srvapi.torrent.torrents.return_value = Response(
            success=True,
            torrents=(MockTorrent(id=1235, name='Some Torrent'),))

        info_cb, err_cb = MagicMock(), MagicMock()
        process = RenameCmd(['--unique', 'id=1235/path/to/file', 'file2'],
                            info_handler=info_cb, error_handler=err_cb, loop=self.loop)
        await process.wait_async()
        self.assertEqual(process.success, True)
        info_cb.assert_not_called()
        err_cb.assert_not_called()

        self.mock_get_relative_path_from_focused.assert_not_called()
        self.mock_select_torrents.assert_called_once_with('id=1235', allow_no_filter=False, discover_torrent=True)
        self.mock_srvapi.torrent.torrents.assert_called_once_with('mock filter', keys=('id',))
        self.assertEqual(self.mock_srvapi.torrent.rename.call_args_list,
                         [call(1235, path='path/to/file', new_name='file2')])
Exemplo n.º 3
0
 async def test_multiple_torrents(self):
     self.api.torrent.response = [
         Response(success=True,
                  msgs=['Added Some Torrent'],
                  torrent=MockTorrent(id=1, name='Some Torrent')),
         Response(success=False,
                  msgs=[ClientError('Something went wrong')],
                  torrent=None),
     ]
     process = AddTorrentsCmd(['some.torrent', 'another.torrent'],
                              loop=self.loop)
     with self.assertLogs(level='INFO') as logged:
         await self.finish(process)
     self.api.torrent.assert_called(2, 'add', ('some.torrent', ),
                                    {'stopped': False},
                                    ('another.torrent', ),
                                    {'stopped': False})
     self.assertEqual(process.success, False)
     self.assert_logged(logged, ('INFO', '^Added Some Torrent$'),
                        ('ERROR', '^Something went wrong$'))
Exemplo n.º 4
0
 async def test_delete_files_short(self):
     tlist = (MockTorrent(id=1, name='Some Torrent', seeds='51'),)
     await self.do(['-d', 'seeds>50'], tlist=tlist, delete=True, success_exp=True,
                   msgs=('Removed Some Torrent',))
Exemplo n.º 5
0
 async def test_remove(self):
     tlist = (MockTorrent(id=1, name='Some Torrent', seeds='51'),)
     await self.do(['seeds>50'], tlist=tlist, delete=False, success_exp=True,
                   msgs=('Removed Some Torrent',))
Exemplo n.º 6
0
 async def test_multiple_matches_are_sorted_by_name(self):
     tlist = (MockTorrent(id=1, name='Torrent B', seeds='51'),
              MockTorrent(id=2, name='Torrent A', seeds='50'))
     await self.do(['mock filter'], tlist=tlist, success_exp=True, errors=())
     self.mock_display_details.assert_called_once_with(2)
Exemplo n.º 7
0
 async def test_single_match(self):
     tlist = (MockTorrent(id=1, name='Torrent A', seeds='50'),)
     await self.do(['mock filter'], tlist=tlist, success_exp=True, errors=())
     self.mock_display_details.assert_called_once_with(1)
Exemplo n.º 8
0
 async def test_delete_files(self):
     tlist = (MockTorrent(id=1, name='Some Torrent', seeds='51'), )
     await self.do(['--delete-files', 'seeds>50'],
                   tlist=tlist,
                   delete=True,
                   msgs=('Removed Some Torrent', ))