def test_updateQueue(self, SLEEP_SHORT, SLEEP_LONG): SLEEP_LONG.return_value = 0 SLEEP_SHORT.return_value = 0 client = Transmission.Client() self.assertIsInstance(client.updateQueue(), tuple)
def test_getQueue(self, SLEEP_SHORT, SLEEP_LONG): SLEEP_LONG.return_value = 0 SLEEP_SHORT.return_value = 0 client = Transmission.Client() self.assertIsInstance(client.getQueue(), list)
def test_getDownloading(self): client = Transmission.Client() torrents = self.getTestTorrents() client.elements['queue'] = torrents result = client.getDownloading(num=50) self.assertEqual(2, len(result))
def test_addTorrentURL(self, SLEEP_SHORT, SLEEP_LONG, mock_parseTransmissionResponse): client = Transmission.Client() #test duplicate torrent testData = [{ 'data': { 'arguments': { 'torrent-duplicate': { 'hashString': 'test_hash' } } }, 'validResult': (1, 'test_hash'), 'response': Responses.duplicate }, { 'data': { 'arguments': { 'torrent-added': { 'hashString': 'test_hash' } } }, 'validResult': (0, 'test_hash'), 'response': Responses.success }, { 'data': {}, 'validResult': (2, Responses.torrentBadRequest), 'response': Responses.torrentBadRequest }, { 'data': {}, 'validResult': (2, Responses.torrentServiceUnavailable), 'response': Responses.torrentServiceUnavailable }, { 'data': {}, 'validResult': (2, Responses.torrentNoResponse), 'response': Responses.torrentNoResponse }, { 'data': {}, 'validResult': (3, Responses.badTorrent), 'response': Responses.badTorrent }, { 'data': {}, 'validResult': (3, Responses.torrentNotFound), 'response': Responses.torrentNotFound }, { 'data': {}, 'validResult': (4, 'Unknown Error/Failed'), 'response': 'xyz' }] for test in testData: mock_parseTransmissionResponse.return_value = (test['data'], 200, test['response']) result = client.addTorrentURL(url='localhost') self.assertEqual(result, test['validResult'])
def __init__(self): # Setup the database object self.database = Databases(dbType=self.defaultDatabaseType) self.logger.info('TransmissionClient INIT') if settings['client']['type'] == 'transmission': self.logger.debug('TorrentClient Setup') self.client = Transmission.Client() else: self.logger.info('TorrentClient Not Defined') raise ValueError('Torrent client type not defined!')
def test_removeExtraTrackers(self, SLEEP_SHORT, SLEEP_LONG, mock_parseTransmissionResponse): SLEEP_LONG.return_value = 0 SLEEP_SHORT.return_value = 0 client = Transmission.Client() mock_parseTransmissionResponse.return_value = ( 'data', '200', Responses.invalidArgument) self.assertIsInstance( client.removeExtraTrackers(hashString='test_hash'), bool) self.assertEqual(client.removeExtraTrackers(hashString='test_hash'), True)
def test_getDownloading(self, mock_getTorrentInfo): mock_getTorrentInfo.return_value = [{ 'minTime': 1, 'minRatio': 1, 'comparison': 'or' }] client = Transmission.Client() torrents = self.getTestTorrents() client.elements['queue'] = torrents result = client.getDownloading(num=50) self.assertEqual(2, len(result))
def test_stopTorrent(self, SLEEP_SHORT, SLEEP_LONG, mock_parseTransmissionResponse): SLEEP_LONG.return_value = 0 SLEEP_SHORT.return_value = 0 client = Transmission.Client() mock_parseTransmissionResponse.return_value = ( 'data', Responses.invalidArgument) self.assertIsInstance(client.stopTorrent(hashString='test_hash'), bool) self.assertEqual(client.stopTorrent(hashString='test_hash'), False) mock_parseTransmissionResponse.return_value = ('data', Responses.success) self.assertIsInstance(client.stopTorrent(hashString='test_hash'), bool) self.assertEqual(client.stopTorrent(hashString='test_hash'), True)
def test_getSlowestSeeds(self, mock_getTorrentInfo): mock_getTorrentInfo.return_value = [{ 'minTime': 1, 'minRatio': 1, 'comparison': 'or' }] client = Transmission.Client() torrents = self.getTestTorrents() client.elements['queue'] = torrents result = client.getSlowestSeeds(num=50) self.assertEqual(3, len(result)) result = client.getSlowestSeeds() self.assertEqual(5, result[0]['status'])
def test_client(self): mock_settings = { 'client': { 'host': '127.0.0.1', 'port': '9000', 'user': '******', 'password': '******', 'rpcLocation': 'trans', 'https': True, 'queue': [], 'sessionId': None } } client = None with patch.dict('flannelfox.settings.settings', mock_settings): client = Transmission.Client() for key, val in mock_settings['client'].items(): self.assertEqual(val, client.elements[key])