Beispiel #1
0
def test_project_detail_invalid_version():
    app = pretend.stub(
        config=pretend.stub(
            cache=pretend.stub(
                browser=False,
                varnish=False,
            ),
        ),
        db=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(
                    lambda proj: "test-project",
                ),
                get_releases=pretend.call_recorder(
                    lambda proj: [{"version": "1.0"}],
                ),
            ),
        ),
    )
    request = pretend.stub()

    project_name = "test-project"

    with pytest.raises(NotFound):
        project_detail(app, request, project_name, "2.0")

    assert app.db.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
Beispiel #2
0
def test_project_detail_invalid_version():
    app = pretend.stub(
        config=pretend.stub(cache=pretend.stub(
            browser=False,
            varnish=False,
        ), ),
        db=pretend.stub(packaging=pretend.stub(
            get_project=pretend.call_recorder(
                lambda proj: {"name": "test-project"}, ),
            get_releases=pretend.call_recorder(
                lambda proj: [{
                    "version": "1.0"
                }], ),
        ), ),
    )
    request = pretend.stub()

    project_name = "test-project"

    with pytest.raises(NotFound):
        project_detail(app, request, project_name, "2.0")

    assert app.db.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
Beispiel #3
0
def test_project_detail_missing_project():
    app = pretend.stub(db=pretend.stub(packaging=pretend.stub(get_project=pretend.call_recorder(lambda proj: None))))
    request = pretend.stub()

    project_name = "test-project"

    with pytest.raises(NotFound):
        project_detail(app, request, project_name)

    assert app.db.packaging.get_project.calls == [pretend.call("test-project")]
Beispiel #4
0
def test_project_detail_missing_project():
    app = pretend.stub(db=pretend.stub(packaging=pretend.stub(
        get_project=pretend.call_recorder(lambda proj: None), ), ), )
    request = pretend.stub()

    project_name = "test-project"

    with pytest.raises(NotFound):
        project_detail(app, request, project_name)

    assert app.db.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
Beispiel #5
0
def test_project_detail_redirects():
    app = pretend.stub(
        config=pretend.stub(cache=pretend.stub(browser=False, varnish=False)),
        db=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(lambda proj: {"name": "test-project"}),
                get_releases=pretend.call_recorder(lambda proj: [{"version": "1.0"}]),
            )
        ),
    )
    request = pretend.stub(
        url_adapter=pretend.stub(build=pretend.call_recorder(lambda *a, **kw: "/projects/test-project/"))
    )

    project_name = "test-Project"
    normalized = "test-project"

    resp = project_detail(app, request, project_name=project_name)

    assert resp.status_code == 301
    assert resp.headers["Location"] == "/projects/test-project/"

    assert resp.headers["Surrogate-Key"] == "project project/{}".format(normalized)

    assert app.db.packaging.get_project.calls == [pretend.call("test-Project")]
    assert app.db.packaging.get_releases.calls == [pretend.call("test-project")]
    assert request.url_adapter.build.calls == [
        pretend.call(
            "warehouse.packaging.views.project_detail",
            {"project_name": "test-project", "version": None},
            force_external=False,
        )
    ]
Beispiel #6
0
def test_project_detail_no_versions():
    app = pretend.stub(
        db=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(lambda proj: {"name": "test-project"}),
                get_releases=pretend.call_recorder(lambda proj: []),
            )
        )
    )
    request = pretend.stub()

    project_name = "test-project"

    with pytest.raises(NotFound):
        project_detail(app, request, project_name)

    assert app.db.packaging.get_project.calls == [pretend.call("test-project")]
    assert app.db.packaging.get_releases.calls == [pretend.call("test-project")]
Beispiel #7
0
def test_project_detail_no_versions():
    app = pretend.stub(db=pretend.stub(packaging=pretend.stub(
        get_project=pretend.call_recorder(
            lambda proj: {"name": "test-project"}, ),
        get_releases=pretend.call_recorder(lambda proj: []),
    ), ), )
    request = pretend.stub()

    project_name = "test-project"

    with pytest.raises(NotFound):
        project_detail(app, request, project_name)

    assert app.db.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
Beispiel #8
0
def test_project_detail_valid(app, version, description, html, camo):
    release = {"description": description, "requires_dist": ["foo", "xyz > 0.1"]}

    app.config = pretend.stub(cache=pretend.stub(browser=False, varnish=False), camo=camo)
    app.db = pretend.stub(
        packaging=pretend.stub(
            get_project=pretend.call_recorder(lambda proj: {"name": "test-project"}),
            get_releases=pretend.call_recorder(lambda proj: [{"version": "2.0"}, {"version": "1.0"}]),
            get_release=pretend.call_recorder(lambda proj, version: release),
            get_download_counts=pretend.call_recorder(lambda proj: {"last_day": 1, "last_week": 7, "last_month": 30}),
            get_reverse_dependencies=pretend.call_recorder(lambda proj: [{"name": "foo"}, {"name": "bar"}]),
            get_downloads=pretend.call_recorder(lambda proj, ver: []),
            get_classifiers=pretend.call_recorder(lambda proj, ver: []),
            get_documentation_url=pretend.call_recorder(lambda proj: None),
            get_bugtrack_url=pretend.call_recorder(lambda proj: None),
            get_users_for_project=pretend.call_recorder(lambda proj: []),
        )
    )

    request = pretend.stub(url_adapter=pretend.stub(build=lambda *a, **kw: "/projects/test-project/"))

    project_name = "test-project"
    normalized = "test-project"

    resp = project_detail(app, request, project_name=project_name, version=version)

    assert resp.status_code == 200
    assert resp.headers["Surrogate-Key"] == "project project/{}".format(normalized)
    assert resp.response.context == {
        "bugtracker": None,
        "classifiers": [],
        "description_html": html,
        "documentation": None,
        "download_counts": {"last_day": 1, "last_week": 7, "last_month": 30},
        "downloads": [],
        "maintainers": [],
        "project": "test-project",
        "release": release,
        "releases": [{"version": "2.0"}, {"version": "1.0"}],
        "reverse_dependencies": [
            {"name": "foo", "url": "/projects/test-project/"},
            {"name": "bar", "url": "/projects/test-project/"},
        ],
        "requirements": [
            {"project_name": "foo", "other": "", "project_url": "/projects/test-project/"},
            {"project_name": "xyz", "other": "> 0.1", "project_url": "/projects/test-project/"},
        ],
    }

    assert app.db.packaging.get_project.calls == [pretend.call("test-project")]
    assert app.db.packaging.get_releases.calls == [pretend.call("test-project")]
    assert app.db.packaging.get_users_for_project.calls == [pretend.call("test-project")]
    assert app.db.packaging.get_reverse_dependencies.calls == [pretend.call("test-project %")]
Beispiel #9
0
def test_project_detail_redirects():
    app = pretend.stub(
        config=pretend.stub(
            cache=pretend.stub(
                browser=False,
                varnish=False,
            ),
        ),
        models=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(
                    lambda proj: "test-project",
                ),
                get_releases=pretend.call_recorder(
                    lambda proj: [{"version": "1.0"}],
                ),
            ),
        ),
    )
    request = pretend.stub(
        url_adapter=pretend.stub(
            build=pretend.call_recorder(
                lambda *a, **kw: "/projects/test-project/",
            ),
        ),
    )

    project_name = "test-Project"
    normalized = "test-project"

    resp = project_detail(app, request, project_name=project_name)

    assert resp.status_code == 301
    assert resp.headers["Location"] == "/projects/test-project/"

    assert resp.headers["Surrogate-Key"] == \
        "project-detail project-detail~{}".format(normalized)

    assert app.models.packaging.get_project.calls == [
        pretend.call("test-Project"),
    ]
    assert app.models.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
    assert request.url_adapter.build.calls == [
        pretend.call(
            "warehouse.packaging.views.project_detail",
            {"project_name": "test-project", "version": None},
            force_external=False,
        ),
    ]
Beispiel #10
0
    def test_prefers_non_yanked_release(self, monkeypatch, db_request):
        project = ProjectFactory.create()

        ReleaseFactory.create(project=project, version="2.0", yanked=True)
        release = ReleaseFactory.create(project=project, version="1.0")

        response = pretend.stub()
        release_detail = pretend.call_recorder(lambda ctx, request: response)
        monkeypatch.setattr(views, "release_detail", release_detail)

        resp = views.project_detail(project, db_request)

        assert resp is response
        assert release_detail.calls == [pretend.call(release, db_request)]
Beispiel #11
0
    def test_only_prereleases(self, monkeypatch, db_request):
        project = ProjectFactory.create()

        ReleaseFactory.create(project=project, version="1.0.dev0")
        ReleaseFactory.create(project=project, version="2.0.dev0")

        release = ReleaseFactory.create(project=project, version="3.0.dev0")

        response = pretend.stub()
        release_detail = pretend.call_recorder(lambda ctx, request: response)
        monkeypatch.setattr(views, "release_detail", release_detail)

        resp = views.project_detail(project, db_request)

        assert resp is response
        assert release_detail.calls == [pretend.call(release, db_request)]
Beispiel #12
0
    def test_normalizing_redirects(self, db_request):
        project = ProjectFactory.create()

        name = project.name.lower()
        if name == project.name:
            name = project.name.upper()

        db_request.matchdict = {"name": name}
        db_request.current_route_path = pretend.call_recorder(
            lambda name: "/project/the-redirect/"
        )

        resp = views.project_detail(project, db_request)

        assert isinstance(resp, HTTPMovedPermanently)
        assert resp.headers["Location"] == "/project/the-redirect/"
        assert db_request.current_route_path.calls == [pretend.call(name=project.name)]
Beispiel #13
0
 def test_missing_release(self, db_request):
     project = ProjectFactory.create()
     resp = views.project_detail(project, db_request)
     assert isinstance(resp, HTTPNotFound)
Beispiel #14
0
 def test_missing_release(self, db_request):
     project = ProjectFactory.create()
     resp = views.project_detail(project, db_request)
     assert isinstance(resp, HTTPNotFound)
Beispiel #15
0
def test_project_detail_valid(version, description):
    release = {
        "description": description,
    }

    template = pretend.stub(
        render=pretend.call_recorder(lambda **ctx: ""),
    )

    app = pretend.stub(
        config=pretend.stub(
            cache=pretend.stub(
                browser=False,
                varnish=False,
            ),
        ),
        models=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(
                    lambda proj: "test-project",
                ),
                get_releases=pretend.call_recorder(
                    lambda proj: [{"version": "2.0"}, {"version": "1.0"}],
                ),
                get_release=pretend.call_recorder(
                    lambda proj, version: release,
                ),
                get_download_counts=pretend.call_recorder(
                    lambda proj: {
                        "last_day": 1,
                        "last_week": 7,
                        "last_month": 30,
                    },
                ),
                get_downloads=pretend.call_recorder(lambda proj, ver: []),
                get_classifiers=pretend.call_recorder(lambda proj, ver: []),
                get_documentation_url=pretend.call_recorder(
                    lambda proj: None,
                ),
                get_bugtrack_url=pretend.call_recorder(lambda proj: None),
                get_users_for_project=pretend.call_recorder(lambda proj: []),
            ),
        ),
        templates=pretend.stub(
            get_template=pretend.call_recorder(lambda t: template),
        ),
    )
    request = pretend.stub()

    project_name = "test-project"
    normalized = "test-project"

    resp = project_detail(
        app,
        request,
        project_name=project_name,
        version=version,
    )

    assert resp.status_code == 200

    assert resp.headers["Surrogate-Key"] == \
        "project-detail project-detail~{}".format(normalized)

    assert app.models.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.models.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
    assert app.models.packaging.get_users_for_project.calls == [
        pretend.call("test-project"),
    ]
Beispiel #16
0
    def test_missing_release(self, db_request):
        project = ProjectFactory.create()

        with pytest.raises(HTTPNotFound):
            views.project_detail(project, db_request)
Beispiel #17
0
def test_project_detail_valid(version, description, camo):
    release = {
        "description": description,
        "requires_dist": ["foo", "xyz > 0.1"]
    }

    template = pretend.stub(
        render=pretend.call_recorder(lambda **ctx: ""),
    )

    app = pretend.stub(
        config=pretend.stub(
            cache=pretend.stub(
                browser=False,
                varnish=False,
            ),
            camo=camo,
        ),
        db=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(
                    lambda proj: "test-project",
                ),
                get_releases=pretend.call_recorder(
                    lambda proj: [{"version": "2.0"}, {"version": "1.0"}],
                ),
                get_release=pretend.call_recorder(
                    lambda proj, version: release,
                ),
                get_download_counts=pretend.call_recorder(
                    lambda proj: {
                        "last_day": 1,
                        "last_week": 7,
                        "last_month": 30,
                    },
                ),
                get_downloads=pretend.call_recorder(lambda proj, ver: []),
                get_classifiers=pretend.call_recorder(lambda proj, ver: []),
                get_documentation_url=pretend.call_recorder(
                    lambda proj: None,
                ),
                get_bugtrack_url=pretend.call_recorder(lambda proj: None),
                get_users_for_project=pretend.call_recorder(lambda proj: []),
            ),
        ),
        templates=pretend.stub(
            get_template=pretend.call_recorder(lambda t: template),
        ),
    )
    request = pretend.stub(
        url_adapter=pretend.stub(build=lambda *a,
                                 **kw: "/projects/test-project/")
    )

    project_name = "test-project"
    normalized = "test-project"

    resp = project_detail(
        app,
        request,
        project_name=project_name,
        version=version,
    )

    assert resp.status_code == 200

    assert resp.headers["Surrogate-Key"] == \
        "project project/{}".format(normalized)

    assert app.db.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_users_for_project.calls == [
        pretend.call("test-project"),
    ]
Beispiel #18
0
def test_project_detail_valid(app, version, description, html, camo):
    release = {
        "description": description,
        "requires_dist": ["foo", "xyz > 0.1"]
    }

    app.config = pretend.stub(
        cache=pretend.stub(
            browser=False,
            varnish=False,
        ),
        camo=camo,
    )
    app.db = pretend.stub(
        packaging=pretend.stub(
            get_project=pretend.call_recorder(
                lambda proj: {"name": "test-project"}, ),
            get_releases=pretend.call_recorder(
                lambda proj: [{
                    "version": "2.0"
                }, {
                    "version": "1.0"
                }], ),
            get_release=pretend.call_recorder(lambda proj, version: release,
                                              ),
            get_download_counts=pretend.call_recorder(
                lambda proj: {
                    "last_day": 1,
                    "last_week": 7,
                    "last_month": 30,
                }, ),
            get_reverse_dependencies=pretend.call_recorder(
                lambda proj: [{
                    'name': 'foo'
                }, {
                    'name': 'bar'
                }]),
            get_downloads=pretend.call_recorder(lambda proj, ver: []),
            get_classifiers=pretend.call_recorder(lambda proj, ver: []),
            get_documentation_url=pretend.call_recorder(lambda proj: None, ),
            get_bugtrack_url=pretend.call_recorder(lambda proj: None),
            get_users_for_project=pretend.call_recorder(lambda proj: []),
        ), )

    request = pretend.stub(url_adapter=pretend.stub(
        build=lambda *a, **kw: "/projects/test-project/"))

    project_name = "test-project"
    normalized = "test-project"

    resp = project_detail(
        app,
        request,
        project_name=project_name,
        version=version,
    )

    assert resp.status_code == 200
    assert resp.headers["Surrogate-Key"] == \
        "project project/{}".format(normalized)
    assert resp.response.context == {
        "bugtracker":
        None,
        "classifiers": [],
        "description_html":
        html,
        "documentation":
        None,
        "download_counts": {
            "last_day": 1,
            "last_week": 7,
            "last_month": 30,
        },
        "downloads": [],
        "maintainers": [],
        "project":
        "test-project",
        "release":
        release,
        "releases": [{
            "version": "2.0"
        }, {
            "version": "1.0"
        }],
        "reverse_dependencies": [{
            'name': 'foo',
            'url': '/projects/test-project/'
        }, {
            'name': 'bar',
            'url': '/projects/test-project/'
        }],
        "requirements": [
            {
                "project_name": "foo",
                "other": "",
                "project_url": "/projects/test-project/",
            },
            {
                "project_name": "xyz",
                "other": "> 0.1",
                "project_url": "/projects/test-project/",
            },
        ],
    }

    assert app.db.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_users_for_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.db.packaging.get_reverse_dependencies.calls == [
        pretend.call("test-project %"),
    ]
Beispiel #19
0
def test_project_detail_valid(version, description):
    release = {
        "description": description,
    }

    template = pretend.stub(
        render=pretend.call_recorder(lambda **ctx: ""),
    )

    app = pretend.stub(
        config=pretend.stub(
            cache=pretend.stub(
                browser=False,
                varnish=False,
            ),
        ),
        models=pretend.stub(
            packaging=pretend.stub(
                get_project=pretend.call_recorder(
                    lambda proj: Project("test-project"),
                ),
                get_releases=pretend.call_recorder(
                    lambda proj: [{"version": "2.0"}, {"version": "1.0"}],
                ),
                get_release=pretend.call_recorder(
                    lambda proj, version: release,
                ),
                get_download_counts=pretend.call_recorder(
                    lambda proj: {
                        "last_day": 1,
                        "last_week": 7,
                        "last_month": 30,
                    },
                ),
                get_downloads=pretend.call_recorder(lambda proj, ver: []),
                get_classifiers=pretend.call_recorder(lambda proj, ver: []),
                get_documentation_url=pretend.call_recorder(
                    lambda proj: None,
                ),
                get_bugtrack_url=pretend.call_recorder(lambda proj: None),
                get_users_for_project=pretend.call_recorder(lambda proj: []),
            ),
        ),
        templates=pretend.stub(
            get_template=pretend.call_recorder(lambda t: template),
        ),
    )
    request = pretend.stub()

    project_name = "test-project"
    normalized = "test-project"

    resp = project_detail(
        app,
        request,
        project_name=project_name,
        version=version,
    )

    assert resp.status_code == 200

    assert resp.headers["Surrogate-Key"] == \
        "project-detail project-detail~{}".format(normalized)

    assert app.models.packaging.get_project.calls == [
        pretend.call("test-project"),
    ]
    assert app.models.packaging.get_releases.calls == [
        pretend.call("test-project"),
    ]
    assert app.models.packaging.get_users_for_project.calls == [
        pretend.call("test-project"),
    ]
Beispiel #20
0
    def test_missing_release(self, db_request):
        project = ProjectFactory.create()

        with pytest.raises(HTTPNotFound):
            views.project_detail(project, db_request)