Пример #1
0
def test_project_not_found():
    app = pretend.stub(models=pretend.stub(packaging=pretend.stub(
        get_project=pretend.call_recorder(lambda p: None), ), ), )
    request = pretend.stub()

    with pytest.raises(NotFound):
        simple.project(app, request, project_name="foo")

    assert app.models.packaging.get_project.calls == [pretend.call("foo")]
Пример #2
0
def test_project_not_found(app):
    app.db = pretend.stub(
        packaging=pretend.stub(
            get_project=pretend.call_recorder(lambda p: None),
        ),
    )

    request = pretend.stub()

    with pytest.raises(NotFound):
        simple.project(app, request, project_name="foo")

    assert app.db.packaging.get_project.calls == [pretend.call("foo")]
Пример #3
0
def test_project(app, monkeypatch,
                 project_name, hosting_mode, release_urls, e_project_urls):
    url_for = lambda *a, **k: "/foo/"
    monkeypatch.setattr(simple, "url_for", url_for)

    app.db = pretend.stub(
        packaging=pretend.stub(
            get_project=pretend.call_recorder(
                lambda p: {'name': project_name},
            ),
            get_file_urls=pretend.call_recorder(lambda p: []),
            get_hosting_mode=pretend.call_recorder(
                lambda p: hosting_mode,
            ),
            get_external_urls=pretend.call_recorder(lambda p: []),
            get_last_serial=pretend.call_recorder(lambda p: 9999),
            get_release_urls=pretend.call_recorder(lambda p: release_urls),
        ),
    )

    request = pretend.stub()
    resp = simple.project(app, request, project_name=project_name)

    assert resp.headers["Link"] == "</foo/>; rel=canonical"
    assert (resp.headers["Surrogate-Key"] ==
            "project project/{}".format(project_name))
    assert resp.response.template.name == "legacy/simple/detail.html"
    assert resp.response.context == {
        "project": project_name,
        "project_urls": e_project_urls,
        "files": [],
        "external_urls": [],
    }

    assert app.db.packaging.get_project.calls == [
        pretend.call(project_name),
    ]
    assert app.db.packaging.get_file_urls.calls == [
        pretend.call(project_name),
    ]
    assert app.db.packaging.get_hosting_mode.calls == [
        pretend.call(project_name),
    ]
    assert app.db.packaging.get_external_urls.calls == [
        pretend.call(project_name),
    ]
    assert app.db.packaging.get_last_serial.calls == [
        pretend.call(project_name),
    ]

    if hosting_mode == "pypi-explicit":
        assert app.db.packaging.get_release_urls.calls == []
    else:
        assert app.db.packaging.get_release_urls.calls == [
            pretend.call(project_name),
        ]
Пример #4
0
def test_project(project_name, hosting_mode, release_urls,
        e_project_urls, monkeypatch):
    response = pretend.stub(status_code=200, headers=Headers())
    render = pretend.call_recorder(lambda *a, **k: response)
    url_for = lambda *a, **k: "/foo/"

    monkeypatch.setattr(simple, "render_response", render)
    monkeypatch.setattr(simple, "url_for", url_for)

    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 p: project_name),
                get_file_urls=pretend.call_recorder(lambda p: []),
                get_hosting_mode=pretend.call_recorder(
                    lambda p: hosting_mode,
                ),
                get_external_urls=pretend.call_recorder(lambda p: []),
                get_last_serial=pretend.call_recorder(lambda p: 9999),
                get_release_urls=pretend.call_recorder(lambda p: release_urls),
            ),
        ),
    )
    request = pretend.stub()

    resp = simple.project(app, request, project_name=project_name)

    assert resp is response
    assert resp.headers["Link"] == "</foo/>; rel=canonical"
    assert (resp.headers["Surrogate-Key"] ==
        "simple simple~{}".format(project_name))

    assert render.calls == [
        pretend.call(
            app, request, "legacy/simple/detail.html",
            project=project_name,
            project_urls=e_project_urls,
            files=[],
            external_urls=[],
        ),
    ]
    assert app.models.packaging.get_project.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_file_urls.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_hosting_mode.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_external_urls.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_last_serial.calls == [
        pretend.call(project_name),
    ]

    if hosting_mode == "pypi-explicit":
        assert app.models.packaging.get_release_urls.calls == []
    else:
        assert app.models.packaging.get_release_urls.calls == [
            pretend.call(project_name),
        ]
Пример #5
0
def test_project(project_name, hosting_mode, release_urls, e_project_urls,
                 monkeypatch):
    response = pretend.stub(status_code=200, headers=Headers())
    render = pretend.call_recorder(lambda *a, **k: response)
    url_for = lambda *a, **k: "/foo/"

    monkeypatch.setattr(simple, "render_response", render)
    monkeypatch.setattr(simple, "url_for", url_for)

    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 p: project_name),
            get_file_urls=pretend.call_recorder(lambda p: []),
            get_hosting_mode=pretend.call_recorder(lambda p: hosting_mode, ),
            get_external_urls=pretend.call_recorder(lambda p: []),
            get_last_serial=pretend.call_recorder(lambda p: 9999),
            get_release_urls=pretend.call_recorder(lambda p: release_urls),
        ), ),
    )
    request = pretend.stub()

    resp = simple.project(app, request, project_name=project_name)

    assert resp is response
    assert resp.headers["Link"] == "</foo/>; rel=canonical"
    assert (resp.headers["Surrogate-Key"] == "simple simple~{}".format(
        project_name))

    assert render.calls == [
        pretend.call(
            app,
            request,
            "legacy/simple/detail.html",
            project=project_name,
            project_urls=e_project_urls,
            files=[],
            external_urls=[],
        ),
    ]
    assert app.models.packaging.get_project.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_file_urls.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_hosting_mode.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_external_urls.calls == [
        pretend.call(project_name),
    ]
    assert app.models.packaging.get_last_serial.calls == [
        pretend.call(project_name),
    ]

    if hosting_mode == "pypi-explicit":
        assert app.models.packaging.get_release_urls.calls == []
    else:
        assert app.models.packaging.get_release_urls.calls == [
            pretend.call(project_name),
        ]