Exemplo n.º 1
0
    def test_compressed_no_uncompress(self):
        tmp_dir = self._make_temp_content([
            'file foo.txt "this is foo.txt\n"',
            'file subdir/bar.txt "bar.txt\n"',
            'file subdir/subberdir/baz.txt "this is baz.txt\n"',
            'file emptyfile.txt',
            'dir emptydir',
        ])

        server = web_server_controller(file_web_server)
        server.start(root_dir=tmp_dir)
        port = server.address[1]

        cache = http_download_cache(temp_file.make_temp_dir(), compressed=True)

        url1 = self._make_url(port, 'foo.txt')
        self.assertFalse(cache.has_url(url1))
        self.assertEqual(0, cache.download_count)
        cached_filename = cache.get_url(url1, uncompress=False)
        tmp_uncompressed_file = self.make_temp_file()
        compressed_file.uncompress(cached_filename, tmp_uncompressed_file)
        self.assertEqual("this is foo.txt\n",
                         file_util.read(tmp_uncompressed_file, codec='utf-8'))

        cached_filename = cache.get_url(url1, uncompress=False)
        tmp_uncompressed_file = self.make_temp_file()
        compressed_file.uncompress(cached_filename, tmp_uncompressed_file)
        self.assertEqual("this is foo.txt\n",
                         file_util.read(tmp_uncompressed_file, codec='utf-8'))

        server.stop()
Exemplo n.º 2
0
    def test_tarball_large(self):
        server = web_server_controller(self._tarball_web_server)
        server.start()
        port = server.address[1]

        url = self._make_url(port, 'sources/large/large-1.2.3.tar.gz')
        tmp = url_util.download_to_temp_file(url,
                                             basename='large-1.2.3.tar.gz')
        self.debug_spew_filename('tmp', tmp)
        self.assertEqual(['kiwi.bin'], archiver.members(tmp))
        self.assertTrue(file_mime.is_gzip(tmp))
        file_util.remove(tmp)

        server.stop()
Exemplo n.º 3
0
    def test_compressed(self):
        tmp_dir = self._make_temp_content([
            'file foo.txt "this is foo.txt\n"',
            'file subdir/bar.txt "bar.txt\n"',
            'file subdir/subberdir/baz.txt "this is baz.txt\n"',
            'file emptyfile.txt',
            'dir emptydir',
        ])

        server = web_server_controller(file_web_server)
        server.start(root_dir=tmp_dir)
        port = server.address[1]

        cache = http_download_cache(temp_file.make_temp_dir(), compressed=True)

        url1 = self._make_url(port, 'foo.txt')
        self.assertFalse(cache.has_url(url1))
        self.assertEqual(0, cache.download_count)
        self.assertEqual("this is foo.txt\n",
                         file_util.read(cache.get_url(url1), codec='utf-8'))
        self.assertTrue(cache.has_url(url1))
        self.assertEqual(1, cache.download_count)
        self.assertEqual("this is foo.txt\n",
                         file_util.read(cache.get_url(url1), codec='utf-8'))
        self.assertEqual(1, cache.download_count)
        self.assertEqual([
            'http___localhost_{}_foo.txt.gz'.format(server.address[1]),
        ], cache.find_all_files(relative=True))

        url2 = self._make_url(port, 'subdir/subberdir/baz.txt')
        self.assertFalse(cache.has_url(url2))
        self.assertEqual("this is baz.txt\n",
                         file_util.read(cache.get_url(url2), codec='utf-8'))
        self.assertEqual("this is baz.txt\n",
                         file_util.read(cache.get_url(url2), codec='utf-8'))
        self.assertTrue(cache.has_url(url2))
        self.assertEqual([
            'http___localhost_{}_foo.txt.gz'.format(port),
            'http___localhost_{}_subdir_subberdir_baz.txt.gz'.format(port),
        ], cache.find_all_files(relative=True))

        server.stop()
Exemplo n.º 4
0
    def xtest_fail_next_request(self):
        server = web_server_controller(self._tarball_web_server)
        server.start()
        port = server.address[1]

        url = self._make_url(port, 'sources/foo/foo-1.2.3.tar.gz')
        tmp = url_util.download_to_temp_file(url, basename='foo-1.2.3.tar.gz')
        self.assertEqual(['apple.txt', 'orange.txt'], archiver.members(tmp))
        file_util.remove(tmp)

        server.fail_next_request(404)

        with self.assertRaises((url_compat.HTTPError, RuntimeError)) as ctx:
            url_util.download_to_temp_file(url, basename='foo-1.2.3.tar.gz')

        tmp = url_util.download_to_temp_file(url, basename='foo-1.2.3.tar.gz')
        self.assertEqual(['apple.txt', 'orange.txt'], archiver.members(tmp))
        file_util.remove(tmp)

        server.stop()
Exemplo n.º 5
0
    def xtest_tarball(self):
        server = web_server_controller(self._tarball_web_server)
        server.start()
        port = server.address[1]

        url = self._make_url(port, 'sources/foo/foo-1.2.3.tar.gz')
        tmp = url_util.download_to_temp_file(url, basename='foo-1.2.3.tar.gz')
        self.debug_spew_filename('tmp', tmp)
        self.assertEqual(['apple.txt', 'orange.txt'], archiver.members(tmp))
        self.assertTrue(file_mime.is_gzip(tmp))
        file_util.remove(tmp)

        url = self._make_url(port, 'sources/bar/bar-1.2.3.zip')
        tmp = url_util.download_to_temp_file(url, basename='bar-1.2.3.zip')
        self.debug_spew_filename('tmp', tmp)
        self.assertEqual(['apple.txt', 'orange.txt'], archiver.members(tmp))
        self.assertTrue(file_mime.is_zip(tmp))
        file_util.remove(tmp)

        server.stop()
Exemplo n.º 6
0
    def xtest_json(self):
        server = web_server_controller(self._json_web_server)
        server.start()
        port = server.address[1]

        url = self._make_url(port, 'foo')
        content = url_compat.urlopen(url).read()
        response = json.loads(content)
        self.assertEqual({
            'payload': 'nice server: /foo\n',
            'count': 1
        }, response)

        url2 = self._make_url(port, 'bar/baz')
        content = url_compat.urlopen(url2).read()
        response = json.loads(content)
        self.assertEqual({
            'payload': 'nice server: /bar/baz\n',
            'count': 2
        }, response)

        server.stop()