-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_controls.py
171 lines (124 loc) · 4.41 KB
/
test_controls.py
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import pytest
from riskmatrix.controls import Button
from riskmatrix.controls import Icon
def test_icon():
icon = Icon('plus')
assert icon() == '<i class="far fa-plus"></i>'
def test_icon_style():
icon = Icon('plus', style=Icon.Style.regular)
assert icon.style == Icon.Style.regular
assert icon() == '<i class="far fa-plus"></i>'
icon = Icon('plus', style=Icon.Style.solid)
assert icon.style == Icon.Style.solid
assert icon() == '<i class="fas fa-plus"></i>'
icon = Icon('plus', style=Icon.Style.light)
assert icon.style == Icon.Style.light
assert icon() == '<i class="fal fa-plus"></i>'
icon = Icon('plus', style=Icon.Style.duotone)
assert icon.style == Icon.Style.duotone
assert icon() == '<i class="fad fa-plus"></i>'
def test_icon_str():
icon = Icon('plus')
assert str(icon) == '<i class="far fa-plus"></i>'
def test_icon_html():
icon = Icon('plus')
assert icon.__html__() == '<i class="far fa-plus"></i>'
def test_button():
button = Button()
assert button() == '<button class="btn" type="button"></button>'
def test_button_name():
button = Button('edit')
assert button() == (
'<button class="btn" name="edit" type="button"></button>'
)
button = Button('edit', url='#')
assert button() == '<a class="btn" href="#" id="edit" role="button"></a>'
def test_button_title():
button = Button(title='Edit')
assert button() == '<button class="btn" type="button">Edit</button>'
# html injection
button = Button(title='<script>')
assert button() == (
'<button class="btn" type="button"><script></button>'
)
def test_button_description():
button = Button(description='Edit')
assert button() == (
'<button class="btn" type="button">'
'<span title="Edit" data-bs-toggle="tooltip"></span>'
'</button>'
)
# html injection
button = Button(description='<script>')
assert button() == (
'<button class="btn" type="button">'
'<span title="<script>" data-bs-toggle="tooltip"></span>'
'</button>'
)
def test_button_url():
button = Button(url='http://example.com')
assert button() == (
'<a class="btn" href="http://example.com" role="button"></a>'
)
def test_button_submit():
with pytest.raises(ValueError, match=r'Submit button requires "name"\.'):
Button(submit=True)
button = Button('save', submit=True)
assert button.name == 'save'
assert button() == (
'<button class="btn" name="save" type="submit" value="save"></button>'
)
def test_button_icon():
button = Button(icon='plus')
assert button() == (
'<button class="btn" type="button">'
'<i class="far fa-plus"></i>'
'</button>'
)
button = Button(icon=Icon('plus', style=Icon.Style.solid))
assert button() == (
'<button class="btn" type="button">'
'<i class="fas fa-plus"></i>'
'</button>'
)
def test_button_modal():
button = Button(modal='#confirm')
assert button() == (
'<button class="btn" data-bs-target="#confirm" data-bs-toggle="modal" '
'type="button"></button>'
)
def test_button_css_class():
button = Button(css_class='btn-primary')
assert button() == (
'<button class="btn btn-primary" type="button"></button>'
)
def test_button_remove_button():
button = Button(remove_button=True)
assert button() == (
'<button class="btn remove-button" type="button"></button>'
)
def test_button_remove_row():
button = Button(remove_row=True)
assert button() == (
'<button class="btn remove-row" type="button"></button>'
)
def test_button_remove_button_and_row():
with pytest.raises(
ValueError, match=r'Can\'t remove both the button and the row\.'
):
Button(remove_button=True, remove_row=True)
def test_button_str():
button = Button()
assert str(button) == '<button class="btn" type="button"></button>'
def test_button_html():
button = Button()
assert button.__html__() == '<button class="btn" type="button"></button>'
def test_button_complex():
button = Button('edit', title='Edit', icon='edit', description='Edit Item')
assert button() == (
'<button class="btn" name="edit" type="button">'
'<span title="Edit Item" data-bs-toggle="tooltip">'
'<i class="far fa-edit"></i> Edit'
'</span>'
'</button>'
)