Example #1
0
    def test_downloadconfig(self):
        dlcfg = DownloadConfigInterface()

        self.assertIsInstance(dlcfg.get_dest_dir(), unicode)
        dlcfg.set_dest_dir(self.session_base_dir)
        self.assertEqual(dlcfg.get_dest_dir(), self.session_base_dir)

        dlcfg.set_corrected_filename("foobar")
        self.assertEqual(dlcfg.get_corrected_filename(), "foobar")

        dlcfg.set_mode(1)
        self.assertEqual(dlcfg.get_mode(), 1)

        dlcfg.set_hops(4)
        self.assertEqual(dlcfg.get_hops(), 4)

        dlcfg.set_safe_seeding(False)
        self.assertFalse(dlcfg.get_safe_seeding())

        dlcfg.set_seeding_mode("abcd")
        self.assertEqual(dlcfg.get_seeding_mode(), "abcd")

        dlcfg.set_selected_files("foo.bar")
        self.assertEqual(dlcfg.get_selected_files(), ["foo.bar"])

        dlcfg.set_channel_download(True)
        self.assertTrue(dlcfg.get_channel_download())
Example #2
0
    def test_user_stopped(self):
        dlcfg = DownloadConfigInterface()
        dlcfg.set_user_stopped(False)
        self.assertFalse(dlcfg.get_user_stopped())

        dlcfg.set_user_stopped(True)
        self.assertTrue(dlcfg.get_user_stopped())
Example #3
0
    def test_downloadconfig(self):
        dlconf = CallbackConfigParser()
        dlconf.add_section('downloadconfig')
        dlconf.set('downloadconfig', 'hops', 5)
        dlcfg = DownloadConfigInterface(dlconf)

        self.assertIsInstance(dlcfg.get_dest_dir(), unicode)
        dlcfg.set_dest_dir(self.session_base_dir)
        self.assertEqual(dlcfg.get_dest_dir(), self.session_base_dir)

        dlcfg.set_corrected_filename("foobar")
        self.assertEqual(dlcfg.get_corrected_filename(), "foobar")

        dlcfg.set_mode(1)
        self.assertEqual(dlcfg.get_mode(), 1)

        dlcfg.set_hops(4)
        self.assertEqual(dlcfg.get_hops(), 4)

        dlcfg.set_safe_seeding(False)
        self.assertFalse(dlcfg.get_safe_seeding())

        dlcfg.set_selected_files("foo.bar")
        self.assertEqual(dlcfg.get_selected_files(), ["foo.bar"])

        dlcfg.set_max_speed(UPLOAD, 1337)
        dlcfg.set_max_speed(DOWNLOAD, 1338)
        self.assertEqual(dlcfg.get_max_speed(UPLOAD), 1337)
        self.assertEqual(dlcfg.get_max_speed(DOWNLOAD), 1338)
Example #4
0
    def test_set_settings(self):
        """
        Testing whether settings in the API can be successfully set
        """
        download = DownloadConfigInterface()
        download.get_credit_mining = lambda: False
        self.session.get_downloads = lambda: [download]

        def verify_response1(_):
            self.assertEqual(download.get_seeding_mode(), 'time')
            self.assertEqual(download.get_seeding_time(), 100)

        self.should_check_equality = False
        post_data = json.dumps({'libtorrent': {'utp': False, 'max_download_rate': 50},
                                'download_defaults': {'seeding_mode': 'time', 'seeding_time': 100}})
        yield self.do_request('settings', expected_code=200, request_type='POST', raw_data=post_data) \
            .addCallback(verify_response1)

        def verify_response2(_):
            self.assertEqual(download.get_seeding_mode(), 'ratio')
            self.assertEqual(download.get_seeding_ratio(), 3)

        post_data = json.dumps({'download_defaults': {'seeding_mode': 'ratio', 'seeding_ratio': 3}})
        yield self.do_request('settings', expected_code=200, request_type='POST', raw_data=post_data) \
            .addCallback(verify_response2)

        download.get_credit_mining = lambda: True

        def verify_response3(_):
            self.assertNotEqual(download.get_seeding_mode(), 'never')

        post_data = json.dumps({'download_defaults': {'seeding_mode': 'never'}})
        yield self.do_request('settings', expected_code=200, request_type='POST', raw_data=post_data) \
            .addCallback(verify_response3)
Example #5
0
    def test_set_settings(self):
        """
        Testing whether settings in the API can be successfully set
        """
        download = DownloadConfigInterface()
        download.get_share_mode = lambda: False
        self.session.get_downloads = lambda: [download]

        old_filter_setting = self.session.tribler_config.get_family_filter_enabled(
        )

        def verify_response1(_):
            self.assertNotEqual(
                self.session.tribler_config.get_family_filter_enabled(),
                old_filter_setting)
            self.assertEqual(download.get_seeding_mode(), 'time')
            self.assertEqual(download.get_seeding_time(), 100)

        self.should_check_equality = False
        post_data = json.dumps({
            'general': {
                'family_filter': not old_filter_setting
            },
            'Tribler': {
                'maxuploadrate': '1234'
            },
            'libtorrent': {
                'utp': False,
                'max_download_rate': 50
            },
            'downloadconfig': {
                'seeding_mode': 'time',
                'seeding_time': 100
            }
        })
        yield self.do_request('settings', expected_code=200, request_type='POST', post_data=post_data, raw_data=True) \
            .addCallback(verify_response1)

        def verify_response2(_):
            self.assertEqual(download.get_seeding_mode(), 'ratio')
            self.assertEqual(download.get_seeding_ratio(), 3)

        post_data = json.dumps(
            {'downloadconfig': {
                'seeding_mode': 'ratio',
                'seeding_ratio': 3
            }})
        yield self.do_request('settings', expected_code=200, request_type='POST', post_data=post_data, raw_data=True) \
            .addCallback(verify_response2)

        download.get_share_mode = lambda: True

        def verify_response3(_):
            self.assertNotEqual(download.get_seeding_mode(), 'never')

        post_data = json.dumps({'downloadconfig': {'seeding_mode': 'never'}})
        yield self.do_request('settings', expected_code=200, request_type='POST', post_data=post_data, raw_data=True) \
            .addCallback(verify_response3)
Example #6
0
    def test_downloadconfig_copy(self):
        dlcfg = DownloadConfigInterface()
        dlcfg_copy = dlcfg.copy()

        self.assertEqual(dlcfg_copy.get_hops(), 0)
Example #7
0
 def test_downloadconfig_set_vod_multiple_files(self):
     dlcfg = DownloadConfigInterface()
     dlcfg.set_mode(DLMODE_VOD)
     dlcfg.set_selected_files(["foo.txt", "bar.txt"])