Beispiel #1
0
    def test_download_http_nocancel(self):
        '''download_url(), HTTP, no cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(open(fname).read(), self.big_file_contents)
        os.unlink(fname)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, [
            'http://localhost:8427/stuff',
            len(self.big_file_contents),
            len(self.big_file_contents)
        ])

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, dest)
        self.assertEqual(open(dest).read(), self.big_file_contents)
        os.unlink(dest)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, [
            'http://localhost:8427/stuff',
            len(self.big_file_contents),
            len(self.big_file_contents)
        ])

        # nonexisting file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)

        # nonexisting server
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://i.do.not.exist:8080/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)
Beispiel #2
0
    def test_download_http_nocancel(self):
        '''download_url(), HTTP, no cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(open(fname).read(), self.big_file_contents)
        os.unlink(fname)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, ['http://localhost:8427/stuff',
            len(self.big_file_contents), len(self.big_file_contents)])

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, dest)
        self.assertEqual(open(dest).read(), self.big_file_contents)
        os.unlink(dest)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress, ['http://localhost:8427/stuff',
            len(self.big_file_contents), len(self.big_file_contents)])

        # nonexisting file
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)

        # nonexisting server
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://i.do.not.exist:8080/nonexisting')
        httpd.stop()
        self.assertEqual(fname, None)

        # one error message about download failure
        self.assert_(ui.pop_error())
        self.assertRaises(IndexError, ui.pop_error)
Beispiel #3
0
    def test_download_http_cancel(self):
        '''download_url(), HTTP, cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        ui.cancel_progress = True
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1]) / len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        ui.cancel_progress = True
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1]) / len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)
Beispiel #4
0
    def test_download_http_cancel(self):
        '''download_url(), HTTP, cancelling'''

        self.stop_capture()

        ui = sandbox.TestUI()

        # temporary file
        httpd.start(8427, OSLib.inst.workdir)
        ui.cancel_progress = True
        (fname, h) = ui.download_url('http://localhost:8427/stuff')
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1])/len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)

        # specified file name
        dest = os.path.join(OSLib.inst.workdir, 'destfile')
        ui.cancel_progress = True
        httpd.start(8427, OSLib.inst.workdir)
        (fname, h) = ui.download_url('http://localhost:8427/stuff', dest)
        httpd.stop()
        self.assertEqual(fname, None)

        self.assertRaises(IndexError, ui.pop_error)

        # we got progress reports
        self.assertEqual(ui.cur_progress[2], len(self.big_file_contents))
        ratio = float(ui.cur_progress[1])/len(self.big_file_contents)
        self.assert_(ratio >= 0.3, ratio)
        self.assert_(ratio < 0.5)
Beispiel #5
0
    def _stop_keyserver(klass):
        '''Stop the keyserver.'''

        httpd.stop()
        shutil.rmtree(os.path.join(OSLib.inst.workdir, 'pks'))
Beispiel #6
0
 def tearDown(self):
     httpd.stop()
     OSLib.inst.ssl_cert_file_paths = self.orig_cert_file_paths
Beispiel #7
0
 def tearDown(self):
     httpd.stop()
     OSLib.inst.ssl_cert_file_paths = self.orig_cert_file_paths