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")
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), ]
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), ]
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=[], ), ]
def test_search_invalid_doctype(): app = pretend.stub(search=pretend.stub(types={})) with pytest.raises(NotFound): search(app, pretend.stub(), "fake")