Пример #1
0
    async def test_check_function(self):
        wanted_keys = ('id', 'name')

        def check_func(torrent):
            self.assertEqual(set(torrent), set(wanted_keys))

            if 'oo' in torrent['name']:
                return (True,
                        'hit: #%d, %s' % (torrent['id'], torrent['name']))
            else:
                return (False,
                        'miss: #%d, %s' % (torrent['id'], torrent['name']))

        response = await self.api._torrent_action(
            method=self.mock_method,
            check=check_func,
            check_keys=wanted_keys,
        )
        self.assertEqual(self.mock_method_args, (1, 3))
        self.assertEqual(self.mock_method_kwargs, {})
        self.assertEqual(response.success, True)
        self.assertEqual(response.torrents, (
            Torrent({
                'id': 1,
                'name': 'Foo'
            }),
            Torrent({
                'id': 3,
                'name': 'Boo'
            }),
        ))
        self.assertEqual(response.msgs, ('hit: #1, Foo', 'hit: #3, Boo'))
        self.assertEqual(response.errors, ('miss: #2, Bar', ))
Пример #2
0
    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'))
Пример #3
0
 async def test_add_torrent_by_hash(self):
     self.daemon.response = rsrc.response_success(
         {'torrent-added': { 'id': 1,
                             'name': rsrc.TORRENTHASH,
                             'hashString': rsrc.TORRENTHASH}}
     )
     response = await self.api.add(rsrc.TORRENTHASH)
     self.assertEqual(response.success, True)
     self.assertEqual(response.torrent, Torrent({'id': 1, 'name': rsrc.TORRENTHASH}))
Пример #4
0
    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', ))
Пример #5
0
 async def test_rpc_method_without_filter(self):
     response = await self.api._torrent_action(method=self.mock_method, )
     self.assertEqual(self.mock_method_args, (1, 2, 3))  # All torrents
     self.assertEqual(self.mock_method_kwargs, {})
     self.assertEqual(response.success, True)
     self.assertEqual(response.torrents, (
         Torrent({
             'id': 1,
             'name': 'Foo'
         }),
         Torrent({
             'id': 2,
             'name': 'Bar'
         }),
         Torrent({
             'id': 3,
             'name': 'Boo'
         }),
     ))
     self.assertEqual(response.msgs, ())
     self.assertEqual(response.errors, ())
Пример #6
0
 async def test_rpc_method_with_kwargs(self):
     response = await self.api._torrent_action(
         torrents=TorrentFilter('name~B'),
         method=self.mock_method,
         method_args={'foo': 'bar'},
     )
     self.assertEqual(self.mock_method_args, (2, 3))
     self.assertEqual(self.mock_method_kwargs, {'foo': 'bar'})
     self.assertEqual(response.success, True)
     self.assertEqual(response.torrents, (
         Torrent({
             'id': 2,
             'name': 'Bar'
         }),
         Torrent({
             'id': 3,
             'name': 'Boo'
         }),
     ))
     self.assertEqual(response.msgs, ('Found 2 ~B torrents', ))
     self.assertEqual(response.errors, ())
Пример #7
0
 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, ())
Пример #8
0
 async def test_rpc_method_without_kwargs(self):
     response = await self.api._torrent_action(
         torrents=TorrentFilter('id=4|id=3'),
         method=self.mock_method,
     )
     self.assertEqual(self.mock_method_args, (3, ))
     self.assertEqual(self.mock_method_kwargs, {})
     self.assertEqual(response.success, True)
     self.assertEqual(response.torrents, (Torrent({
         'id': 3,
         'name': 'Boo'
     }), ))
     self.assertEqual(response.msgs, ('Found 1 id=4|id=3 torrent', ))
     self.assertEqual(response.errors, ())
Пример #9
0
 def test_name_is_default(self):
     tids = SingleTorrentFilter('=foo').apply(tlist, key='id')
     self.assertEqual(set(tids), {
         1,
     })
     tids = SingleTorrentFilter('!=foo').apply(tlist, key='id')
     self.assertEqual(set(tids), {2, 3, 4})
     tids = SingleTorrentFilter('~foo').apply(tlist, key='id')
     self.assertEqual(set(tids), {1, 4})
     tids = SingleTorrentFilter('!~foo').apply(tlist, key='id')
     self.assertEqual(set(tids), {2, 3})
     tl = list(tlist)
     tl.append(Torrent({'id': 999, 'name': ''}))
     tids = SingleTorrentFilter('!').apply(tl, key='id')
     self.assertEqual(set(tids), {
         999,
     })
Пример #10
0
 async def test_add_torrent_by_local_file(self):
     self.daemon.response = rsrc.response_success({
         'torrent-added': {
             'id': 1,
             'name': 'Test Torrent',
             'hashString': rsrc.TORRENTHASH
         }
     })
     response = await self.api.add(rsrc.TORRENTFILE)
     self.assertEqual(response.success, True)
     self.assertEqual(response.torrent,
                      Torrent({
                          'id': 1,
                          'name': 'Test Torrent'
                      }))
     self.assertEqual(response.msgs, ('Added Test Torrent', ))
     self.assertEqual(response.errors, ())
Пример #11
0
from stig.client.filters.tfilter import (SingleTorrentFilter, TorrentFilter)
from stig.client.aiotransmission.torrent import Torrent

import unittest

tlist = (
    Torrent({
        'id': 1,
        'name': 'Foo',
        'downloadDir': '/some/path/to/torrents',
        'isStalled': True,
        'isPrivate': False,
        'status': 6,
        'percentDone': 1,
        'peersConnected': 0,
        'rateUpload': 0,
        'rateDownload': 0,
        'downloadedEver': 0
    }),
    Torrent({
        'id': 2,
        'name': 'Bar123',
        'downloadDir': '/some/path/to/torrents',
        'isStalled': False,
        'isPrivate': True,
        'status': 4,
        'percentDone': 0.0235,
        'peersConnected': 3,
        'rateUpload': 58e3,
        'rateDownload': 384e3,
        'downloadedEver': 0
Пример #12
0
from stig.client.filters.tfilter import (SingleTorrentFilter, TorrentFilter)
from stig.client.aiotransmission.torrent import Torrent

import unittest

tlist = (
    Torrent({
        'id': 1,
        'name': 'Foo',
        'downloadDir': '/some/path/to/torrents',
        'isPrivate': False,
        'status': 6,
        'percentDone': 1,
        'eta': -1,
        'peersConnected': 0,
        'rateUpload': 0,
        'rateDownload': 0,
        'downloadedEver': 0,
        'metadataPercentComplete': 1,
        'trackerStats': []
    }),
    Torrent({
        'id': 2,
        'name': 'Bar123',
        'downloadDir': '/some/path/to/torrents/',
        'isPrivate': True,
        'status': 4,
        'percentDone': 0.0235,
        'eta': 84600,
        'peersConnected': 3,
        'rateUpload': 58e3,
Пример #13
0
import asyncio
from types import SimpleNamespace

import asynctest

from stig.client.aiotransmission.torrent import Torrent
from stig.client.filters.torrent import TorrentFilter
from stig.client.trequestpool import TorrentRequestPool
from stig.client.utils import Response

FAKE_TORRENTS = (Torrent({
    'id': 1,
    'name': 'foo',
    'rateDownload': 50,
    'rateUpload': 100,
    'totalSize': 10e3,
    'isPrivate': False
}),
                 Torrent({
                     'id': 2,
                     'name': 'bar',
                     'rateDownload': 0,
                     'rateUpload': 0,
                     'totalSize': 10e6,
                     'isPrivate': True
                 }),
                 Torrent({
                     'id': 3,
                     'name': 'baz',
                     'rateDownload': 0,
                     'rateUpload': 0,
Пример #14
0
from stig.client.aiotransmission.torrent import Torrent
from stig.client.filters.tfilter import TorrentFilter
from stig.client.utils import Response

import asynctest
import asyncio
from types import SimpleNamespace

import logging
log = logging.getLogger(__name__)

FAKE_TORRENTS = (Torrent({
    'id': 1,
    'name': 'foo',
    'status': 3,
    'isStalled': False,
    'rateDownload': 50,
    'rateUpload': 100,
    'totalSize': 10e3
}),
                 Torrent({
                     'id': 2,
                     'name': 'bar',
                     'status': 0,
                     'isStalled': True,
                     'rateDownload': 0,
                     'rateUpload': 0,
                     'totalSize': 10e6
                 }),
                 Torrent({
                     'id': 3,