Пример #1
0
    def test_settings(self):
        plugin = QBittorrentClientPlugin()
        settings = {'host': 'localhost', 'username': '******', 'password': '******'}
        self.assertIsNone(plugin.get_settings())
        plugin.set_settings(settings)
        readed_settings = plugin.get_settings()

        self.assertEqual({'host': 'localhost', 'port': None, 'username': '******'}, readed_settings)
Пример #2
0
    def test_check_connection_successfull(self, qbittorrent_client):
        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        self.assertNotEqual(False, plugin.check_connection())

        qbittorrent_client.assert_called_with(host=QBittorrentClientPlugin.ADDRESS_FORMAT.format('localhost', QBittorrentClientPlugin.DEFAULT_PORT),
                                               username='******', password='******')
Пример #3
0
 def test_find_torrent_no_settings(self):
     with patch.object(monitorrent.plugins.clients.qbittorrent.requests.Session, 'post', side_effect=Exception):
         plugin = QBittorrentClientPlugin()
         torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
         settings = {'host': self.bad_host, 'port': self.bad_port, 'username': self.bad_login,
                     'password': self.bad_password}
         plugin.set_settings(settings)
         torrent = plugin.find_torrent(torrent_hash)
         self.assertFalse(torrent)
Пример #4
0
    def test_find_torrent_failed_with_exception(self, qbittorrent_client):
        client = qbittorrent_client.return_value
        client.torrents_info.side_effect = qbittorrentapi.HTTP500Error

        plugin = QBittorrentClientPlugin()
        torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)
        self.assertFalse(plugin.find_torrent(torrent_hash))
Пример #5
0
    def test_find_torrent_no_settings(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value
        
        torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
        plugin = QBittorrentClientPlugin()

        torrent = plugin.find_torrent(torrent_hash)

        rpc_client.torrents_info.assert_not_called()
Пример #6
0
    def test_find_torrent_failed(self, qbittorrent_client):
        client = qbittorrent_client.return_value
        client.torrents_info.return_value = []

        plugin = QBittorrentClientPlugin()
        torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)
        self.assertFalse(plugin.find_torrent(torrent_hash))
Пример #7
0
 def test_check_connection_successfull(self):
     plugin = QBittorrentClientPlugin()
     settings = {
         'host': self.real_host,
         'port': self.real_port,
         'username': self.real_login,
         'password': self.real_password
     }
     plugin.set_settings(settings)
     self.assertTrue(plugin.check_connection())
Пример #8
0
    def test_add_torrent_with_settings_success(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value
        rpc_client.torrents_add.return_value = 'Ok.'

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertEqual('Ok.', plugin.add_torrent(torrent, TopicSettings("/path/to/download")))
Пример #9
0
    def test_add_torrent_success(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value
        rpc_client.torrents_add.return_value = 'Ok.'

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertEqual('Ok.', plugin.add_torrent(torrent, None))
Пример #10
0
    def test_get_download_dir_error(self, qbittorrent_client):
        client = qbittorrent_client.return_value
        client.app_default_save_path.side_effect = qbittorrentapi.HTTP500Error

        plugin = QBittorrentClientPlugin()

        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        self.assertIsNone(plugin.get_download_dir())
Пример #11
0
    def test_remove_torrent_failed(self, qbittorrent_client):
        client = qbittorrent_client.return_value
        client.torrents_delete.side_effect = qbittorrentapi.HTTP500Error

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertFalse(plugin.remove_torrent(torrent))
Пример #12
0
    def test_check_connection_failed(self, post_mock):
        response = Response()
        response.status_code = 404
        post_mock.return_value = response

        plugin = QBittorrentClientPlugin()
        self.password_ = {'host': self.bad_host, 'port': self.bad_port, 'username': self.bad_login,
                          'password': self.bad_password}
        settings = self.password_
        plugin.set_settings(settings)
        self.assertFalse(plugin.check_connection())
Пример #13
0
    def test_remove_torrent_success(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value
        rpc_client.torrents_delete.return_value = 'Ok.'

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertTrue(plugin.remove_torrent(torrent))

        rpc_client.torrents_delete.assert_called_once_with(hashes=[torrent.lower()])
Пример #14
0
    def test_find_torrent(self, get_mock):
        response = Response()
        response._content = b'[{"added_on":"2016-04-09T20:24:17","completion_on":null,"dlspeed":0,"eta":8640000,"f_l_piece_prio":false,"force_start":false,"hash":"d27c8e30f0c12afe84735b57f6463266b118acea","label":"","name":"Ment.v.zakone.9.2015.HDTVRip.Files-x","num_complete":12,"num_incomplete":42,"num_leechs":0,"num_seeds":0,"priority":1,"progress":0.073527365922927856,"ratio":0.022764846784523337,"save_path":"Downloads","seq_dl":false,"size":5776162816,"state":"pausedDL","super_seeding":false,"upspeed":0}]'
        get_mock.return_value = response

        plugin = QBittorrentClientPlugin()
        torrent_hash = "D27C8E30F0C12AFE84735B57F6463266B118ACEA"
        settings = {'host': self.real_host, 'username': self.real_login,
                    'password': self.real_password}
        plugin.set_settings(settings)
        torrent = plugin.find_torrent(torrent_hash)
        self.assertEqual(torrent['date_added'], datetime(2016, 4, 9, 20, 24, 17, tzinfo=pytz.reference.Local))
        self.assertEqual(torrent['name'], 'Ment.v.zakone.9.2015.HDTVRip.Files-x')
Пример #15
0
    def test_check_connection_failed(self, qbittorrent_client):
        qbittorrent_client.side_effect = qbittorrentapi.APIConnectionError

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        self.assertFalse(plugin.check_connection())

        qbittorrent_client.assert_called_with(
            host=QBittorrentClientPlugin.ADDRESS_FORMAT.format(
                'localhost', QBittorrentClientPlugin.DEFAULT_PORT),
            username='******',
            password='******')
Пример #16
0
    def test_find_torrent_failed(self, post_mock, get_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200
        post_mock.return_value = response
        get_mock.side_effect = Exception('boom')

        plugin = QBittorrentClientPlugin()
        torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
        settings = {'host': self.real_host, 'port': self.real_port, 'username': self.real_login,
                    'password': self.real_password}
        plugin.set_settings(settings)
        torrent = plugin.find_torrent(torrent_hash)
        self.assertFalse(torrent)
Пример #17
0
    def test_remove_torrent_failed(self, post_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200

        post_mock.side_effect = [response, Exception('boom')]

        plugin = QBittorrentClientPlugin()
        settings = {'host': self.real_host, 'port': self.real_port, 'username': self.real_login,
                    'password': self.real_password}
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertFalse(plugin.remove_torrent(torrent))
Пример #18
0
    def test_check_connection_failed(self, post_mock):
        response = Response()
        response.status_code = 404
        post_mock.return_value = response

        plugin = QBittorrentClientPlugin()
        self.password_ = {
            'host': self.bad_host,
            'port': self.bad_port,
            'username': self.bad_login,
            'password': self.bad_password
        }
        settings = self.password_
        plugin.set_settings(settings)
        self.assertFalse(plugin.check_connection())
Пример #19
0
    def test_remove_torrent_success(self, post_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200
        good_response = Response()
        good_response.status_code = 200
        post_mock.side_effect = [response, good_response]

        plugin = QBittorrentClientPlugin()
        settings = {'host': self.real_host, 'port': self.real_port, 'username': self.real_login,
                    'password': self.real_password}
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertTrue(plugin.remove_torrent(torrent))
Пример #20
0
 def test_find_torrent_no_settings(self):
     with patch.object(
             monitorrent.plugins.clients.qbittorrent.requests.Session,
             'post',
             side_effect=Exception):
         plugin = QBittorrentClientPlugin()
         torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
         settings = {
             'host': self.bad_host,
             'port': self.bad_port,
             'username': self.bad_login,
             'password': self.bad_password
         }
         plugin.set_settings(settings)
         torrent = plugin.find_torrent(torrent_hash)
         self.assertFalse(torrent)
Пример #21
0
    def test_remove_torrent_failed(self, post_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200

        post_mock.side_effect = [response, Exception('boom')]

        plugin = QBittorrentClientPlugin()
        settings = {
            'host': self.real_host,
            'port': self.real_port,
            'username': self.real_login,
            'password': self.real_password
        }
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertFalse(plugin.remove_torrent(torrent))
Пример #22
0
    def test_find_torrent(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value

        torrent_hash = "D27C8E30F0C12AFE84735B57F6463266B118ACEA"
        date_added = datetime(2015, 10, 9, 12, 3, 55, tzinfo=pytz.reference.LocalTimezone())

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent_info = new('torrent', {'name': 'Torrent 1', 'info': new('info', {'added_on': date_added.astimezone(pytz.utc).timestamp()})})
        rpc_client.torrents_info.return_value = [torrent_info]

        torrent = plugin.find_torrent(torrent_hash)

        self.assertEqual({'name': 'Torrent 1', 'date_added': date_added.astimezone(pytz.utc)}, torrent)

        rpc_client.torrents_info.assert_called_once_with(hashes=[torrent_hash.lower()])
Пример #23
0
    def test_find_torrent_failed(self, post_mock, get_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200
        post_mock.return_value = response
        get_mock.side_effect = Exception('boom')

        plugin = QBittorrentClientPlugin()
        torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
        settings = {
            'host': self.real_host,
            'port': self.real_port,
            'username': self.real_login,
            'password': self.real_password
        }
        plugin.set_settings(settings)
        torrent = plugin.find_torrent(torrent_hash)
        self.assertFalse(torrent)
Пример #24
0
    def test_find_torrent_for_33_version(self, get_mock):
        response = Response()
        response._content = b'[{"added_on":1481781596,"completion_on":null,"dlspeed":0,"eta":8640000,"f_l_piece_prio":false,"force_start":false,"hash":"d27c8e30f0c12afe84735b57f6463266b118acea","label":"","name":"Ment.v.zakone.9.2015.HDTVRip.Files-x","num_complete":12,"num_incomplete":42,"num_leechs":0,"num_seeds":0,"priority":1,"progress":0.073527365922927856,"ratio":0.022764846784523337,"save_path":"Downloads","seq_dl":false,"size":5776162816,"state":"pausedDL","super_seeding":false,"upspeed":0}]'
        get_mock.return_value = response

        plugin = QBittorrentClientPlugin()
        torrent_hash = "D27C8E30F0C12AFE84735B57F6463266B118ACEA"
        settings = {
            'host': self.real_host,
            'username': self.real_login,
            'password': self.real_password
        }
        plugin.set_settings(settings)
        torrent = plugin.find_torrent(torrent_hash)
        self.assertEqual(torrent['date_added'],
                         datetime(2016, 12, 15, 5, 59, 56, tzinfo=pytz.utc))
        self.assertEqual(torrent['name'],
                         'Ment.v.zakone.9.2015.HDTVRip.Files-x')
Пример #25
0
    def test_remove_torrent_success(self, post_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200
        good_response = Response()
        good_response.status_code = 200
        post_mock.side_effect = [response, good_response]

        plugin = QBittorrentClientPlugin()
        settings = {
            'host': self.real_host,
            'port': self.real_port,
            'username': self.real_login,
            'password': self.real_password
        }
        plugin.set_settings(settings)

        torrent = b'torrent'
        self.assertTrue(plugin.remove_torrent(torrent))
Пример #26
0
    def test_decorate_post_method(self):
        client = QBittorrentPluginTest.ClassWithPostMethod()
        client = QBittorrentClientPlugin._decorate_post(client)

        (args, kwargs) = client._post(torrent_contents=[('file.torrent',
                                                         b'torrent')])

        assert len(args) == 0
        assert len(kwargs) == 1
        assert 'files' in kwargs
        assert kwargs['files'] == [('file.torrent', b'torrent')]
Пример #27
0
    def test_get_download_dir_error(self, mocker):
        target = "{0}:{1}/".format(self.real_host, self.real_port)

        mocker.post(target + "login", text="Ok.")

        error = {'error': 500}
        mocker.get(target + "query/preferences",
                   status_code=500,
                   text=json.dumps(error))

        settings = {
            'host': self.real_host,
            'port': self.real_port,
            'username': self.real_login,
            'password': self.real_password
        }

        plugin = QBittorrentClientPlugin()
        plugin.set_settings(settings)

        assert plugin.get_download_dir() is None
Пример #28
0
    def test_settings(self):
        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        self.assertIsNone(plugin.get_settings())
        plugin.set_settings(settings)
        readed_settings = plugin.get_settings()

        expected = {'host': 'localhost', 'port': None, 'username': '******'}
        self.assertEqual(expected, readed_settings)
Пример #29
0
    def test_remove_torrent_failed(self, qbittorrent_client):
        qbittorrent_client.side_effect = qbittorrentapi.HTTP500Error

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent = b'torrent'
        with pytest.raises(qbittorrentapi.HTTP500Error) as e:
            plugin.remove_torrent(torrent)
Пример #30
0
    def test_get_download_dir_error(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value
        qbittorrent_client.side_effect = qbittorrentapi.HTTP500Error

        plugin = QBittorrentClientPlugin()

        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        with pytest.raises(qbittorrentapi.HTTP500Error) as e:
            plugin.get_download_dir()
Пример #31
0
    def test_get_download_dir_success(self, qbittorrent_client):
        rpc_client = qbittorrent_client.return_value
        rpc_client.app_default_save_path.return_value = '/mnt/media/downloads'

        plugin = QBittorrentClientPlugin()

        assert plugin.get_download_dir() is None

        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        assert plugin.get_download_dir() == u'/mnt/media/downloads'

        rpc_client.app_default_save_path.assert_called_once()
Пример #32
0
    def test_add_torrent_failed(self, post_mock):
        response = Response()
        response._content = b"Ok."
        response.status_code = 200

        post_mock.side_effect = [response, Exception('boom')]

        plugin = QBittorrentClientPlugin()
        settings = self.DEFAULT_SETTINGS
        plugin.set_settings(settings)

        torrent = b'torrent'
        with pytest.raises(Exception) as e:
            plugin.add_torrent(torrent, None)
Пример #33
0
    def test_settings(self):
        plugin = QBittorrentClientPlugin()
        settings = {
            'host': 'localhost',
            'username': '******',
            'password': '******'
        }
        self.assertIsNone(plugin.get_settings())
        plugin.set_settings(settings)
        readed_settings = plugin.get_settings()

        self.assertEqual(
            {
                'host': 'localhost',
                'port': None,
                'username': '******'
            }, readed_settings)
Пример #34
0
    def test_get_download_dir_success(self, mocker):
        target = "{0}:{1}/".format(self.real_host, self.real_port)

        mocker.post(target + "login", text="Ok.")

        preferences = {'save_path': u'/mnt/media/downloads'}
        mocker.get(target + "query/preferences", text=json.dumps(preferences))

        plugin = QBittorrentClientPlugin()

        assert plugin.get_download_dir() is None

        settings = {
            'host': self.real_host,
            'port': self.real_port,
            'username': self.real_login,
            'password': self.real_password
        }
        plugin.set_settings(settings)

        assert plugin.get_download_dir() == u'/mnt/media/downloads'
Пример #35
0
 def test_check_connection_successfull(self):
     plugin = QBittorrentClientPlugin()
     settings = {'host': self.real_host, 'port': self.real_port, 'username': self.real_login,
                 'password': self.real_password}
     plugin.set_settings(settings)
     self.assertTrue(plugin.check_connection())
Пример #36
0
 def test_remove_torrent_bad_settings(self):
     plugin = QBittorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.remove_torrent(torrent))
Пример #37
0
 def test_remove_torrent_bad_settings(self):
     plugin = QBittorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.remove_torrent(torrent))
Пример #38
0
 def test_add_torrent_bad_settings(self):
     plugin = QBittorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.add_torrent(torrent, None))
Пример #39
0
 def test_add_torrent_bad_settings(self):
     plugin = QBittorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.add_torrent(torrent, None))