Exemplo n.º 1
0
    def test_404_when_missing_file(self, db_request, pyramid_config):
        @pretend.call_recorder
        def raiser(path):
            raise FileNotFoundError

        storage_service = pretend.stub(get=raiser)

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "source/{}/{}/{}".format(
            project.name[0], project.name, file_.filename
        )

        db_request.matchdict["path"] = path
        db_request.log = pretend.stub(
            error=pretend.call_recorder(lambda event, **kw: None),
        )
        db_request.find_service = pretend.call_recorder(
            lambda iface: storage_service
        )

        resp = views.packages(db_request)

        assert isinstance(resp, HTTPNotFound)
        assert db_request.find_service.calls == [pretend.call(IFileStorage)]
        assert storage_service.get.calls == [pretend.call(path)]
        assert db_request.log.error.calls == [
            pretend.call("missing file data", path=path),
        ]
Exemplo n.º 2
0
    def test_404_when_missing_file(self, db_request, pyramid_config):
        @pretend.call_recorder
        def opener(path, mode):
            raise fs.errors.ResourceNotFoundError

        pyramid_config.registry["filesystems"] = {
            "packages": pretend.stub(open=opener),
        }

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "source/{}/{}/{}".format(
            project.name[0], project.name, file_.filename
        )

        db_request.matchdict["path"] = path
        db_request.log = pretend.stub(
            error=pretend.call_recorder(lambda event, **kw: None),
        )

        resp = views.packages(db_request)

        assert isinstance(resp, HTTPNotFound)
        assert opener.calls == [pretend.call(path, mode="rb")]
        assert db_request.log.error.calls == [
            pretend.call("missing file data", path=path),
        ]
Exemplo n.º 3
0
    def test_404_when_no_sig(self, db_request, pyramid_config):
        pyramid_config.registry["filesystems"] = {
            "packages": pretend.stub(exists=lambda p: False),
        }

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "/".join([
            file_.blake2_256_digest[:2],
            file_.blake2_256_digest[2:4],
            file_.blake2_256_digest[4:],
            file_.filename + ".asc",
        ])

        db_request.matchdict["path"] = path

        resp = views.packages(db_request)

        assert isinstance(resp, HTTPNotFound)
Exemplo n.º 4
0
    def test_404_when_no_sig(self, db_request, pyramid_config):
        pyramid_config.registry["filesystems"] = {
            "packages": pretend.stub(exists=lambda p: False),
        }

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "/".join([
            file_.blake2_256_digest[:2],
            file_.blake2_256_digest[2:4],
            file_.blake2_256_digest[4:],
            file_.filename + ".asc",
        ])

        db_request.matchdict["path"] = path

        resp = views.packages(db_request)

        assert isinstance(resp, HTTPNotFound)
Exemplo n.º 5
0
    def test_404_when_missing_file(self, db_request, pyramid_config):
        @pretend.call_recorder
        def raiser(path):
            raise FileNotFoundError

        storage_service = pretend.stub(get=raiser)

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "source/{}/{}/{}".format(project.name[0], project.name,
                                        file_.filename)

        db_request.matchdict["path"] = path
        db_request.log = pretend.stub(
            error=pretend.call_recorder(lambda event, **kw: None), )
        db_request.find_service = pretend.call_recorder(
            lambda iface: storage_service)

        resp = views.packages(db_request)

        assert isinstance(resp, HTTPNotFound)
        assert db_request.find_service.calls == [pretend.call(IFileStorage)]
        assert storage_service.get.calls == [pretend.call(path)]
        assert db_request.log.error.calls == [
            pretend.call("missing file data", path=path),
        ]
Exemplo n.º 6
0
    def test_serves_signature_file(self, db_request):
        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
            has_signature=True,
        )

        path = "/".join([
            file_.blake2_256_digest[:2],
            file_.blake2_256_digest[2:4],
            file_.blake2_256_digest[4:],
            file_.filename + ".asc",
        ])

        storage_service = pretend.stub(
            get=pretend.call_recorder(
                lambda path: io.BytesIO(b"some data for the fake file")
            )
        )

        db_request.matchdict["path"] = path
        db_request.find_service = pretend.call_recorder(
            lambda iface: storage_service
        )

        resp = views.packages(db_request)

        # We want to roundtrip our upload_time
        last_modified = datetime_utils.parse_date(
            datetime_utils.serialize_date(file_.upload_time)
        )

        assert db_request.find_service.calls == [pretend.call(IFileStorage)]
        assert storage_service.get.calls == [pretend.call(path)]

        assert resp.content_type == "application/octet-stream"
        assert resp.content_encoding is None
        assert resp.etag == file_.md5_digest
        assert resp.last_modified == last_modified
        assert resp.content_length is None
        # This needs to be last, as accessing resp.body sets the content_length
        assert resp.body == b"some data for the fake file"
Exemplo n.º 7
0
    def test_serves_signature_file(self, db_request):
        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
            has_signature=True,
        )

        path = "/".join([
            file_.blake2_256_digest[:2],
            file_.blake2_256_digest[2:4],
            file_.blake2_256_digest[4:],
            file_.filename + ".asc",
        ])

        storage_service = pretend.stub(get=pretend.call_recorder(
            lambda path: io.BytesIO(b"some data for the fake file")))

        db_request.matchdict["path"] = path
        db_request.find_service = pretend.call_recorder(
            lambda iface: storage_service)

        resp = views.packages(db_request)

        # We want to roundtrip our upload_time
        last_modified = datetime_utils.parse_date(
            datetime_utils.serialize_date(file_.upload_time))

        assert db_request.find_service.calls == [pretend.call(IFileStorage)]
        assert storage_service.get.calls == [pretend.call(path)]

        assert resp.content_type == "application/octet-stream"
        assert resp.content_encoding is None
        assert resp.etag == file_.md5_digest
        assert resp.last_modified == last_modified
        assert resp.content_length is None
        # This needs to be last, as accessing resp.body sets the content_length
        assert resp.body == b"some data for the fake file"
Exemplo n.º 8
0
    def test_serves_signature_file(self, db_request, pyramid_config):
        memfs = fs.memoryfs.MemoryFS()

        pyramid_config.registry["filesystems"] = {"packages": memfs}

        project = ProjectFactory.create()
        release = ReleaseFactory.create(project=project)
        file_ = FileFactory.create(
            release=release,
            filename="{}-{}.tar.gz".format(project.name, release.version),
            python_version="source",
        )

        path = "source/{}/{}/{}.asc".format(
            project.name[0], project.name, file_.filename
        )

        memfs.makedir(os.path.dirname(path), recursive=True)
        memfs.setcontents(path, b"some data for the fake file")

        db_request.matchdict["path"] = path

        resp = views.packages(db_request)

        # We want to roundtrip our upload_time
        last_modified = datetime_utils.parse_date(
            datetime_utils.serialize_date(file_.upload_time)
        )

        assert resp.content_type == "application/octet-stream"
        assert resp.content_encoding is None
        assert resp.etag == file_.md5_digest
        assert resp.last_modified == last_modified
        assert resp.content_length is None
        # This needs to be last, as accessing resp.body sets the content_length
        assert resp.body == b"some data for the fake file"
Exemplo n.º 9
0
 def test_404_when_no_file(self, db_request):
     db_request.matchdict["path"] = "source/f/foo/foo-1.0.tar.gz"
     resp = views.packages(db_request)
     assert isinstance(resp, HTTPNotFound)
Exemplo n.º 10
0
 def test_404_when_no_file(self, db_request):
     db_request.matchdict["path"] = "source/f/foo/foo-1.0.tar.gz"
     resp = views.packages(db_request)
     assert isinstance(resp, HTTPNotFound)