File: test_pagination.py

package info (click to toggle)
bootstrap-flask 2.2.0%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 25,396 kB
  • sloc: python: 2,218; makefile: 24
file content (32 lines) | stat: -rw-r--r-- 1,277 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from flask import render_template_string, request
from flask_sqlalchemy import SQLAlchemy


def test_render_pagination(app, client):
    db = SQLAlchemy(app)

    class Message(db.Model):
        id = db.Column(db.Integer, primary_key=True)

    @app.route('/pagination')
    def test():
        db.drop_all()
        db.create_all()
        for i in range(100):  # noqa: F841
            msg = Message()
            db.session.add(msg)
        db.session.commit()
        page = request.args.get('page', 1, type=int)
        pagination = Message.query.paginate(page=page, per_page=10)
        messages = pagination.items
        return render_template_string('''
                                {% from 'bootstrap5/pagination.html' import render_pagination %}
                                {{ render_pagination(pagination) }}
                                ''', pagination=pagination, messages=messages)

    response = client.get('/pagination')
    data = response.get_data(as_text=True)
    assert '<nav aria-label="Page navigation">' in data
    assert '<a class="page-link" href="#">1 <span class="sr-only">(current)</span></a>' not in data
    assert '<li class="page-item active" aria-current="page">' in data
    assert '<a class="page-link" href="#">1</a>' in data