Пример #1
0
 def test_settings(self):
     plugin = UTorrentClientPlugin()
     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_find_torrent(self):
     plugin = UTorrentClientPlugin()
     torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
     settings = {'host': self.real_host, 'username': self.real_login,
                 'password': self.real_password}
     plugin.set_settings(settings)
     torrent = plugin.find_torrent(torrent_hash)
     self.assertIsNone(torrent['date_added'])
     self.assertIsNotNone(torrent['name'])
Пример #3
0
    def test_check_connection_failed(self):
        import monitorrent.plugins.clients.utorrent

        with patch.object(monitorrent.plugins.clients.utorrent.requests.Session, 'get', side_effect=Exception):
            plugin = UTorrentClientPlugin()
            settings = {'host': self.bad_host, 'port': self.bad_port, 'username': self.bad_login,
                        'password': self.bad_password}
            plugin.set_settings(settings)
            self.assertFalse(plugin.check_connection())
Пример #4
0
 def test_find_torrent(self):
     plugin = UTorrentClientPlugin()
     torrent_hash = "8347DD6415598A7409DFC3D1AB95078F959BFB93"
     settings = {'host': self.real_host, 'username': self.real_login,
                 'password': self.real_password}
     plugin.set_settings(settings)
     torrent = plugin.find_torrent(torrent_hash)
     self.assertIsNone(torrent['date_added'])
     self.assertIsNotNone(torrent['name'])
Пример #5
0
    def test_check_connection_failed(self):
        import monitorrent.plugins.clients.utorrent

        with patch.object(monitorrent.plugins.clients.utorrent.requests.Session, 'get', side_effect=Exception):
            plugin = UTorrentClientPlugin()
            settings = {'host': self.bad_host, 'port': self.bad_port, 'username': self.bad_login,
                        'password': self.bad_password}
            plugin.set_settings(settings)
            self.assertFalse(plugin.check_connection())
Пример #6
0
 def test_check_connection_successfull(self):
     plugin = UTorrentClientPlugin()
     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())
Пример #7
0
 def test_find_torrent_failed(self, get_mock):
     response = Response()
     response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
     get_mock.return_value = response
     plugin = UTorrentClientPlugin()
     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)
Пример #8
0
    def test_find_torrent_no_settings(self):
        import monitorrent.plugins.clients.utorrent

        with patch.object(monitorrent.plugins.clients.utorrent.requests.Session, 'get', side_effect=Exception):
            plugin = UTorrentClientPlugin()
            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)
Пример #9
0
    def test_find_torrent_no_settings(self):
        import monitorrent.plugins.clients.utorrent

        with patch.object(monitorrent.plugins.clients.utorrent.requests.Session, 'get', side_effect=Exception):
            plugin = UTorrentClientPlugin()
            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)
Пример #10
0
    def test_remove_torrent_failed(self, get_mock):
        response = Response()
        response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
        response.status_code = 200

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

        plugin = UTorrentClientPlugin()
        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))
Пример #11
0
    def test_remove_torrent_success(self, get_mock):
        response = Response()
        response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
        response.status_code = 200
        good_response = Response()
        good_response.status_code = 200
        get_mock.side_effect = [response, good_response]

        plugin = UTorrentClientPlugin()
        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))
Пример #12
0
 def test_find_torrent_failed(self, get_mock):
     response = Response()
     response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
     get_mock.return_value = response
     plugin = UTorrentClientPlugin()
     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)
Пример #13
0
    def test_add_torrent_success(self, post_mock, get_mock):
        response = Response()
        response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
        response.status_code = 200
        good_response = Response()
        good_response.status_code = 200
        get_mock.return_value = response
        post_mock.return_value = good_response

        plugin = UTorrentClientPlugin()
        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.add_torrent(torrent, None))
Пример #14
0
    def test_add_torrent_failed(self, post_mock, get_mock):
        response = Response()
        response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
        response.status_code = 200

        get_mock.return_value = response
        post_mock.side_effect = Exception('boom')

        plugin = UTorrentClientPlugin()
        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.add_torrent(torrent, None))
Пример #15
0
 def test_settings(self):
     plugin = UTorrentClientPlugin()
     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)
Пример #16
0
    def test_remove_torrent_failed(self, get_mock):
        response = Response()
        response._content = b"<html><div id=''token'' style=''display:none;''>FKWBGjUDYXGNX7I-UBo5-UiWK1MUOaDmjjrorxOTzmEq3b0lWpr4no8v-FYAAAAA</div></html>"
        response.status_code = 200

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

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

        torrent = b'torrent'
        with pytest.raises(Exception) as e:
            plugin.remove_torrent(torrent)
Пример #17
0
 def test_check_connection_successfull(self):
     plugin = UTorrentClientPlugin()
     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())
Пример #18
0
 def test_remove_torrent_bad_settings(self, get_mock):
     plugin = UTorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.remove_torrent(torrent))
Пример #19
0
 def test_add_torrent_bad_settings(self, get_mock):
     plugin = UTorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.add_torrent(torrent, None))
Пример #20
0
 def test_remove_torrent_bad_settings(self, get_mock):
     plugin = UTorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.remove_torrent(torrent))
Пример #21
0
 def test_add_torrent_bad_settings(self, get_mock):
     plugin = UTorrentClientPlugin()
     torrent = b'torrent'
     self.assertFalse(plugin.add_torrent(torrent, None))