def _test_focus_download(self, other_canceled, extract, log):
        extract.return_value = ("http://foo/bar", "myfile")
        current_dest = os.path.join("dest", "myfile")
        other_dest = os.path.join("dest", "otherfile")
        curent_download = download_manager.Download("http://url", current_dest)
        curent_download.wait = Mock()
        curent_download.set_progress = Mock()
        other_download = download_manager.Download("http://url", other_dest)
        # fake some download activity
        self.dl_manager._downloads = {
            current_dest: curent_download,
            other_dest: other_download,
        }
        curent_download.is_running = Mock(return_value=True)
        other_download.is_running = Mock(return_value=True)

        build_info = Mock(build="info")
        result = self.dl_manager.focus_download(build_info)

        self.assertFalse(curent_download.is_canceled())
        curent_download.wait.assert_called_with()

        self.assertEqual(other_download.is_canceled(), other_canceled)

        log.info.assert_called_with("Downloading build from: http://foo/bar")

        self.assertEqual(result, current_dest)
        self.assertEqual(result, build_info.build_file)
示例#2
0
    def test_focus_download(self, extract):
        extract.return_value = ('http://foo/bar', 'myfile')
        current_dest = os.path.join('dest', 'myfile')
        other_dest = os.path.join('dest', 'otherfile')
        curent_download = download_manager.Download('http://url', current_dest)
        curent_download.wait = Mock()
        curent_download.set_progress = Mock()
        other_download = download_manager.Download('http://url', other_dest)
        # fake some download activity
        self.dl_manager._downloads = {
            current_dest: curent_download,
            other_dest: other_download,
        }
        curent_download.is_running = Mock(return_value=True)
        other_download.is_running = Mock(return_value=True)

        result = self.dl_manager.focus_download({'build': 'info'})

        curent_download.set_progress.assert_called_with(
            download_manager.download_progress)
        self.assertFalse(curent_download.is_canceled())
        curent_download.wait.assert_called_with()

        self.assertTrue(other_download.is_canceled())

        self.dl_manager.logger.info.assert_called_with(
            "Downloading build from: http://foo/bar")

        self.assertEquals(result, current_dest)
示例#3
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.addCleanup(shutil.rmtree, self.tempdir)
     self.finished = Mock()
     self.session, self.session_response = mock_session()
     self.tempfile = os.path.join(self.tempdir, 'dest')
     self.dl = download_manager.Download('http://url', self.tempfile,
                                         finished_callback=self.finished,
                                         chunk_size=4,
                                         session=self.session)