コード例 #1
0
ファイル: test_views.py プロジェクト: DalavanCloud/warehouse
def test_search_page_invalid_page():
    app = pretend.stub(
        search=pretend.stub(types={"fake": pretend.stub(SEARCH_LIMIT=25)}), )
    request = pretend.stub(args={"q": "Django", "page": "abc"})

    with pytest.raises(NotFound):
        search(app, request, "fake")
コード例 #2
0
ファイル: test_views.py プロジェクト: Ivoz/warehouse
def test_search_page_invalid_page():
    app = pretend.stub(
        search=pretend.stub(types={"fake": pretend.stub(SEARCH_LIMIT=25)}),
    )
    request = pretend.stub(args={"q": "Django", "page": "abc"})

    with pytest.raises(NotFound):
        search(app, request, "fake")
コード例 #3
0
ファイル: test_views.py プロジェクト: DalavanCloud/warehouse
def test_search_page_less_than_zero(app):
    app.search = pretend.stub(types={
        "fake":
        pretend.stub(
            SEARCH_LIMIT=25,
            search=pretend.call_recorder(
                lambda q, l, o: {"hits": {
                    "hits": []
                }},
            ),
        ),
    }, )

    request = pretend.stub(args={"q": "Django", "page": "-1"})

    resp = search(app, request, "fake")

    assert resp.response.template.name == "search/results.html"
    assert resp.response.context == {
        "query": "Django",
        "total": 0,
        "pages": mock.ANY,
        "results": [],
    }
    assert app.search.types["fake"].search.calls == [
        pretend.call("Django", 25, 0),
    ]
コード例 #4
0
ファイル: test_views.py プロジェクト: AaronLaw/warehouse
def test_search_page_less_than_zero(app):
    app.search = pretend.stub(
        types={
            "fake": pretend.stub(
                SEARCH_LIMIT=25,
                search=pretend.call_recorder(
                    lambda q, l, o: {"hits": {"hits": []}},
                ),
            ),
        },
    )

    request = pretend.stub(args={"q": "Django", "page": "-1"})

    resp = search(app, request, "fake")

    assert resp.response.template.name == "search/results.html"
    assert resp.response.context == {
        "query": "Django",
        "total": 0,
        "pages": mock.ANY,
        "results": [],
    }
    assert app.search.types["fake"].search.calls == [
        pretend.call("Django", 25, 0),
    ]
コード例 #5
0
def test_search_page_less_than_zero(monkeypatch):
    response = pretend.stub()
    render_response = pretend.call_recorder(lambda *a, **kw: response)

    monkeypatch.setattr(views, "render_response", render_response)

    app = pretend.stub(
        search=pretend.stub(
            types={
                "fake": pretend.stub(
                    SEARCH_LIMIT=25,
                    search=pretend.call_recorder(
                        lambda q, l, o: {"hits": {"hits": []}},
                    ),
                ),
            },
        ),
    )

    request = pretend.stub(args={"q": "Django", "page": "-1"})

    resp = search(app, request, "fake")

    assert resp is response
    assert app.search.types["fake"].search.calls == [
        pretend.call("Django", 25, 0),
    ]
    assert render_response.calls == [
        pretend.call(
            app,
            request,
            "search/results.html",
            query="Django",
            total=0,
            pages=mock.ANY,
            results=[],
        ),
    ]
コード例 #6
0
def test_search_invalid_doctype():
    app = pretend.stub(search=pretend.stub(types={}))

    with pytest.raises(NotFound):
        search(app, pretend.stub(), "fake")