File: test_render_icon.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 (95 lines) | stat: -rw-r--r-- 2,976 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
from flask import render_template_string


def test_render_icon(app, client):
    @app.route('/icon')
    def icon():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart') }}
        ''')

    @app.route('/icon-size')
    def icon_size():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart', 32) }}
        ''')

    @app.route('/icon-style')
    def icon_style():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart', color='primary') }}
        ''')

    @app.route('/icon-color')
    def icon_color():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart', color='green') }}
        ''')

    @app.route('/icon-title')
    def icon_title():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart', title='Heart') }}
        ''')

    @app.route('/icon-desc')
    def icon_desc():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart', desc='A heart.') }}
        ''')

    response = client.get('/icon')
    data = response.get_data(as_text=True)
    assert 'bootstrap-icons.svg#heart' in data
    assert 'width="1em"' in data
    assert 'height="1em"' in data

    response = client.get('/icon-size')
    data = response.get_data(as_text=True)
    assert 'bootstrap-icons.svg#heart' in data
    assert 'width="32"' in data
    assert 'height="32"' in data

    response = client.get('/icon-style')
    data = response.get_data(as_text=True)
    assert 'bootstrap-icons.svg#heart' in data
    assert 'text-primary' in data

    response = client.get('/icon-color')
    data = response.get_data(as_text=True)
    assert 'bootstrap-icons.svg#heart' in data
    assert 'style="color: green"' in data

    response = client.get('/icon-title')
    data = response.get_data(as_text=True)
    assert 'bootstrap-icons.svg#heart' in data
    assert '<title>Heart</title>' in data

    response = client.get('/icon-desc')
    data = response.get_data(as_text=True)
    assert 'bootstrap-icons.svg#heart' in data
    assert '<desc>A heart.</desc>' in data


def test_render_icon_config(app, client):
    app.config['BOOTSTRAP_ICON_SIZE'] = 100
    app.config['BOOTSTRAP_ICON_COLOR'] = 'success'

    @app.route('/icon')
    def icon():
        return render_template_string('''
        {% from 'bootstrap4/utils.html' import render_icon %}
            {{ render_icon('heart') }}
        ''')

    response = client.get('/icon')
    data = response.get_data(as_text=True)
    assert 'width="100"' in data
    assert 'height="100"' in data
    assert 'text-success' in data