Example #1
0
    def test_cache_remote_file(self, filestore, httpget, gen, xom):
        link = gen.pypi_package_link("pytest-1.8.zip", md5=False)
        entry = filestore.maplink(link, "root", "pypi", "pytest")
        assert not entry.hash_spec and not entry.file_exists()
        filestore.keyfs.restart_as_write_transaction()
        headers = {
            "content-length": "3",
            "last-modified": "Thu, 25 Nov 2010 20:00:27 GMT",
        }
        httpget.url2response[link.url] = dict(status_code=200,
                                              headers=headers,
                                              raw=BytesIO(b"123"))
        for part in iter_cache_remote_file(xom, entry):
            pass
        rheaders = entry.gethttpheaders()
        assert rheaders["content-length"] == "3"
        assert rheaders["content-type"] in zip_types
        assert rheaders["last-modified"] == headers["last-modified"]
        bytes = entry.file_get_content()
        assert bytes == b"123"

        # reget entry and check about content
        filestore.keyfs.restart_as_write_transaction()
        entry = filestore.get_file_entry(entry.relpath)
        assert entry.file_exists()
        assert entry.hash_value == getdigest(bytes, entry.hash_type)
        assert entry.file_size() == 3
        rheaders = entry.gethttpheaders()
        assert entry.file_get_content() == b"123"
Example #2
0
 def test_iterfile_remote_no_headers(self, filestore, httpget, gen, xom):
     link = gen.pypi_package_link("pytest-1.8.zip", md5=False)
     entry = filestore.maplink(link, "root", "pypi", "pytest")
     assert not entry.hash_spec
     headers = {}
     httpget.url2response[link.url] = dict(status_code=200,
                                           headers=headers,
                                           raw=BytesIO(b"123"))
     for part in iter_cache_remote_file(xom, entry):
         pass
     rheaders = entry.gethttpheaders()
     assert rheaders["content-length"] == "3"
     assert rheaders["content-type"] in zip_types
     assert entry.file_get_content() == b"123"
Example #3
0
 def test_iterfile_remote_error_size_mismatch(self, filestore, httpget, gen,
                                              xom):
     link = gen.pypi_package_link("pytest-3.0.zip", md5=False)
     entry = filestore.maplink(link, "root", "pypi", "pytest")
     assert not entry.hash_spec
     headers = {
         "content-length": "3",
         "last-modified": "Thu, 25 Nov 2010 20:00:27 GMT",
         "content-type": "application/zip"
     }
     httpget.url2response[link.url] = dict(status_code=200,
                                           headers=headers,
                                           raw=BytesIO(b"1"))
     with pytest.raises(ValueError):
         for part in iter_cache_remote_file(xom, entry):
             pass
Example #4
0
 def test_iterfile_remote_error_md5(self, filestore, httpget, gen, xom):
     link = gen.pypi_package_link("pytest-3.0.zip")
     entry = filestore.maplink(link, "root", "pypi", "pytest")
     assert entry.hash_spec and entry.hash_spec == link.hash_spec
     headers = ResponseHeaders({
         "content-length": "3",
         "last-modified": "Thu, 25 Nov 2010 20:00:27 GMT",
         "content-type": "application/zip"
     })
     httpget.url2response[link.url_nofrag] = dict(status_code=200,
                                                  headers=headers,
                                                  raw=BytesIO(b"123"))
     with pytest.raises(ValueError, match=link.md5):
         for part in iter_cache_remote_file(xom, entry):
             pass
     assert not entry.file_exists()
Example #5
0
 def test_iterfile_remote_nosize(self, filestore, httpget, gen, xom):
     link = gen.pypi_package_link("pytest-3.0.zip", md5=False)
     entry = filestore.maplink(link, "root", "pypi", "pytest")
     assert not entry.hash_spec
     headers = {
         "last-modified": "Thu, 25 Nov 2010 20:00:27 GMT",
         "content-length": None,
     }
     assert entry.file_size() is None
     httpget.url2response[link.url] = dict(status_code=200,
                                           headers=headers,
                                           raw=BytesIO(b"1"))
     for part in iter_cache_remote_file(xom, entry):
         pass
     assert entry.file_get_content() == b"1"
     entry2 = filestore.get_file_entry(entry.relpath)
     assert entry2.file_size() == 1
     rheaders = entry.gethttpheaders()
     assert rheaders["last-modified"] == headers["last-modified"]
     assert rheaders["content-type"] in zip_types