def test_transmission_error(self): tc = MagicMock() tc_add_torrent = raise_exception tc.add_torrent = tc_add_torrent success = transmissionrpc_add_torrent(tc, 'fake_file') self.assertFalse(success)
def test_ok(self): tc = MagicMock() tc_add_torrent = MagicMock() tc.add_torrent = tc_add_torrent success = transmissionrpc_add_torrent(tc, 'fake_file') tc_add_torrent.assert_called_once() self.assertTrue(success)
def check_torrent_files(): tc = transmissionrpc_client() if not tc: current_app.logger.info('No connetion to remote transmission, stop task.') return dbc = DropBoxClient() for f in dbc.folder(current_app.config['TRANSMISSION_DROPBOX_TORRENTS_FOLDER']): with NamedTemporaryFile() as tf: tf.write(dbc.file(f)) success = transmissionrpc_add_torrent(tc, 'file://%s' % tf.name) if success: dbc.rm_file(f) current_app.logger.info('Successfully added torrent "%s".' % f) else: current_app.logger.info('Torrent "%s" not added, skip it.' % f)