async def test_get_torrents_by_ids(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Torrent1' }, { 'id': 2, 'name': 'Torrent2' }, { 'id': 3, 'name': 'Torrent3' }, ) response = await self.api.torrents(torrents=(1, 3)) self.assertEqual(response.success, True) self.assert_torrentkeys_equal('id', response.torrents, 1, 3) self.assert_torrentkeys_equal('name', response.torrents, 'Torrent1', 'Torrent3') response = await self.api.torrents(torrents=(2, )) self.assertEqual(response.success, True) self.assert_torrentkeys_equal('id', response.torrents, 2) self.assert_torrentkeys_equal('name', response.torrents, 'Torrent2') response = await self.api.torrents(torrents=()) self.assertEqual(response.success, True) self.assertEqual(response.torrents, ()) response = await self.api.torrents(torrents=(42, 23)) self.assertEqual(response.success, False) self.assertEqual(response.torrents, ()) self.assertIn('42', str(response.msgs[0])) self.assertIn('23', str(response.msgs[1]))
async def test_get_torrents_by_filter(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Foo' }, { 'id': 2, 'name': 'Bar' }, { 'id': 3, 'name': 'Boo' }, ) response = await self.api.torrents(torrents=TorrentFilter('name=Foo')) self.assertEqual(response.success, True) self.assert_torrentkeys_equal('id', response.torrents, 1) self.assert_torrentkeys_equal('name', response.torrents, 'Foo') response = await self.api.torrents(torrents=TorrentFilter('name~oo')) self.assertEqual(response.success, True) self.assert_torrentkeys_equal('id', response.torrents, 1, 3) self.assert_torrentkeys_equal('name', response.torrents, 'Foo', 'Boo') response = await self.api.torrents(torrents=TorrentFilter('name=Nope')) self.assertEqual(response.success, False) self.assertEqual(response.torrents, ()) self.assertIn('Nope', str(response.msgs[0]))
async def test_subtract_from_current_limit_when_enabled(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Foo', 'uploadLimit': 100, 'uploadLimited': True }, { 'id': 2, 'name': 'Bar', 'uploadLimit': 200, 'uploadLimited': True }, ) await self.api.adjust_limit_rate_up(TorrentFilter('id=1|id=2'), -50e3) self.assert_request({ 'method': 'torrent-set', 'arguments': { 'ids': [1], 'uploadLimited': True, 'uploadLimit': 50 } }) self.assert_request({ 'method': 'torrent-set', 'arguments': { 'ids': [2], 'uploadLimited': True, 'uploadLimit': 150 } })
async def test_enable_rate_limit(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Foo', 'uploadLimit': 100, 'uploadLimited': False }, { 'id': 2, 'name': 'Bar', 'uploadLimit': 200, 'uploadLimited': False }, ) response = await self.api.set_limit_rate_up(TorrentFilter('id=1|id=2'), True) self.assert_request({ 'method': 'torrent-set', 'arguments': { 'ids': [1, 2], 'uploadLimited': True } }) self.assertEqual(response.success, True)
async def test_get_all_torrents(self): self.daemon.response = rsrc.response_torrents( {'id': 1, 'name': 'Torrent1'}, {'id': 2, 'name': 'Torrent2'}, ) torrents = (await self.api.torrents()).torrents self.assert_torrentkeys_equal('id', torrents, 1, 2) self.assert_torrentkeys_equal('name', torrents, 'Torrent1', 'Torrent2')
async def setUp(self): await super().setUp() self.mock_method_args = None self.mock_method_kwargs = None self.daemon.response = rsrc.response_torrents( {'id': 1, 'name': 'Foo'}, {'id': 2, 'name': 'Bar'}, {'id': 3, 'name': 'Boo'}, )
async def test_get_torrents_by_ids(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Torrent1' }, { 'id': 2, 'name': 'Torrent2' }, { 'id': 3, 'name': 'Torrent3' }, ) response = await self.api.torrents(torrents=(1, 3)) self.assertEqual(response.success, True) self.assertEqual(response.torrents, (Torrent({ 'id': 1, 'name': 'Torrent1' }), Torrent({ 'id': 3, 'name': 'Torrent3' }))) self.assertEqual(response.msgs, ()) self.assertEqual(response.errors, ()) response = await self.api.torrents(torrents=(2, )) self.assertEqual(response.success, True) self.assertEqual(response.torrents, (Torrent({ 'id': 2, 'name': 'Torrent2' }), )) self.assertEqual(response.msgs, ()) self.assertEqual(response.errors, ()) response = await self.api.torrents(torrents=()) self.assertEqual(response.success, True) self.assertEqual(response.torrents, ()) self.assertEqual(response.msgs, ()) self.assertEqual(response.errors, ()) response = await self.api.torrents(torrents=(4, 5)) self.assertEqual(response.success, False) self.assertEqual(response.torrents, ()) self.assertEqual(response.msgs, ()) self.assertEqual(response.errors, ('No torrent with ID: 4', 'No torrent with ID: 5'))
async def test_subtract_from_current_limit_when_disabled(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Foo', 'uploadLimit': 100, 'uploadLimited': False }, { 'id': 2, 'name': 'Bar', 'uploadLimit': 200, 'uploadLimited': False }, ) await self.api.adjust_limit_rate_up(TorrentFilter('id=1|id=2'), -50e3) self.daemon.requests == () # Assert no requests were sent
async def test_get_torrents_by_filter(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Foo' }, { 'id': 2, 'name': 'Bar' }, { 'id': 3, 'name': 'Boo' }, ) response = await self.api.torrents(torrents=TorrentFilter('name=Foo')) self.assertEqual(response.success, True) self.assertEqual(response.torrents, (Torrent({ 'id': 1, 'name': 'Foo' }), )) self.assertEqual(response.msgs, ('Found 1 =Foo torrent', )) self.assertEqual(response.errors, ()) response = await self.api.torrents(torrents=TorrentFilter('name~oo')) self.assertEqual(response.success, True) self.assertEqual(response.torrents, (Torrent({ 'id': 1, 'name': 'Foo' }), Torrent({ 'id': 3, 'name': 'Boo' }))) self.assertEqual(response.msgs, ('Found 2 ~oo torrents', )) self.assertEqual(response.errors, ()) response = await self.api.torrents(torrents=TorrentFilter('name=Nope')) self.assertEqual(response.success, False) self.assertEqual(response.torrents, ()) self.assertEqual(response.msgs, ()) self.assertEqual(response.errors, ('No matching torrents: =Nope', ))
async def test_get_all_torrents(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Torrent1' }, { 'id': 2, 'name': 'Torrent2' }, ) response = await self.api.torrents() self.assertEqual(response.success, True) self.assertEqual(response.torrents, (Torrent({ 'id': 1, 'name': 'Torrent1' }), Torrent({ 'id': 2, 'name': 'Torrent2' }))) self.assertEqual(response.msgs, ()) self.assertEqual(response.errors, ())
async def test_set_absolute_rate_limit(self): self.daemon.response = rsrc.response_torrents( { 'id': 1, 'name': 'Foo', 'uploadLimit': 100, 'uploadLimited': False }, { 'id': 2, 'name': 'Bar', 'uploadLimit': 200, 'uploadLimited': True }, ) await self.api.set_limit_rate_up(TorrentFilter('id=1|id=2'), 1e6) self.assert_request({ 'method': 'torrent-set', 'arguments': { 'ids': [1, 2], 'uploadLimited': True, 'uploadLimit': 1000 } })