Esempio n. 1
0
def test_get_pagination_ten_pages_on_page_7():
    request = RequestFactory().get('/')
    context = {
        "results": {
            "hits": {
                "total": {
                    "value": 199
                }
            }
        },
        "query": BASIC_QUERY
    }
    get_pagination(request, context, 7)
    assert 11 == len(context['pages'])

    page = context['pages'].pop(0)
    assert "first" == page['type']

    page = context['pages'].pop(0)
    assert "prev" == page['type']

    page = context['pages'].pop(0)
    assert "ellipsis" == page['type']

    page = context['pages'].pop(0)
    assert "number" == page['type']
    assert "5" == page['label']

    page = context['pages'].pop(0)
    assert "number" == page['type']
    assert "6" == page['label']

    page = context['pages'].pop(0)
    assert "number" == page['type']
    assert "7" == page['label']
    assert page['active']

    page = context['pages'].pop(0)
    assert "number" == page['type']
    assert "8" == page['label']

    page = context['pages'].pop(0)
    assert "number" == page['type']
    assert "9" == page['label']

    page = context['pages'].pop(0)
    assert "ellipsis" == page['type']

    page = context['pages'].pop(0)
    assert "next" == page['type']

    page = context['pages'].pop(0)
    assert "last" == page['type']
Esempio n. 2
0
def test_get_pagination_single_page():
    request = RequestFactory().get('/')
    context = {
        "results": {
            "hits": {
                "total": {
                    "value": 5
                }
            }
        },
        "query": BASIC_QUERY
    }
    get_pagination(request, context, 1)
    assert 1 == len(context['pages'])

    page = context['pages'].pop(0)
    assert "number" == page['type']
    assert "1" == page['label']
    assert page['active']