-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtests.py
693 lines (585 loc) · 25.2 KB
/
tests.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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
from django import forms
from django.contrib.admin.widgets import AdminSplitDateTime
from django.contrib.messages import constants as DEFAULT_MESSAGE_LEVELS
from django.forms.formsets import formset_factory
from django.template import engines
from django.test import TestCase
from .exceptions import BootstrapError
from .text import text_value, text_concat
from .utils import add_css_class, render_tag
try:
from html.parser import HTMLParser
except ImportError:
from HTMLParser import HTMLParser
RADIO_CHOICES = (
('1', 'Radio 1'),
('2', 'Radio 2'),
)
MEDIA_CHOICES = (
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
('unknown', 'Unknown'),
)
class TestForm(forms.Form):
"""
Form with a variety of widgets to test bootstrap4 rendering.
"""
date = forms.DateField(required=False)
datetime = forms.SplitDateTimeField(widget=AdminSplitDateTime(), required=False)
subject = forms.CharField(
max_length=100,
help_text='my_help_text',
required=True,
widget=forms.TextInput(attrs={'placeholder': 'placeholdertest'}),
)
password = forms.CharField(widget=forms.PasswordInput)
message = forms.CharField(required=False, help_text='<i>my_help_text</i>')
sender = forms.EmailField(
label='Sender © unicode',
help_text='E.g., "me@example.com"')
secret = forms.CharField(initial=42, widget=forms.HiddenInput)
cc_myself = forms.BooleanField(
required=False,
help_text='cc stands for "carbon copy." You will get a copy in your mailbox.'
)
select1 = forms.ChoiceField(choices=RADIO_CHOICES)
select2 = forms.MultipleChoiceField(
choices=RADIO_CHOICES,
help_text='Check as many as you like.',
)
select3 = forms.ChoiceField(choices=MEDIA_CHOICES)
select4 = forms.MultipleChoiceField(
choices=MEDIA_CHOICES,
help_text='Check as many as you like.',
)
category1 = forms.ChoiceField(
choices=RADIO_CHOICES, widget=forms.RadioSelect)
category2 = forms.MultipleChoiceField(
choices=RADIO_CHOICES,
widget=forms.CheckboxSelectMultiple,
help_text='Check as many as you like.',
)
category3 = forms.ChoiceField(
widget=forms.RadioSelect, choices=MEDIA_CHOICES)
category4 = forms.MultipleChoiceField(
choices=MEDIA_CHOICES,
widget=forms.CheckboxSelectMultiple,
help_text='Check as many as you like.',
)
addon = forms.CharField(
widget=forms.TextInput(attrs={'addon_before': 'before', 'addon_after': 'after'}),
)
required_css_class = 'bootstrap4-req'
# Set this to allow tests to work properly in Django 1.10+
# More information, see issue #337
use_required_attribute = False
def clean(self):
cleaned_data = super(TestForm, self).clean()
raise forms.ValidationError(
"This error was added to show the non field errors styling.")
return cleaned_data
class TestFormWithoutRequiredClass(TestForm):
required_css_class = ''
def render_template(text, context=None):
"""
Create a template ``text`` that first loads bootstrap4.
"""
template = engines['django'].from_string(text)
if not context:
context = {}
return template.render(context)
def render_template_with_bootstrap(text, context=None):
"""
Create a template ``text`` that first loads bootstrap4.
"""
if not context:
context = {}
return render_template("{% load bootstrap4 %}" + text, context)
def render_template_with_form(text, context=None):
"""
Create a template ``text`` that first loads bootstrap4.
"""
if not context:
context = {}
if 'form' not in context:
context['form'] = TestForm()
return render_template_with_bootstrap(text, context)
def render_formset(formset=None, context=None):
"""
Create a template that renders a formset
"""
if not context:
context = {}
context['formset'] = formset
return render_template_with_form('{% bootstrap_formset formset %}', context)
def render_form(form=None, context=None):
"""
Create a template that renders a form
"""
if not context:
context = {}
if form:
context['form'] = form
return render_template_with_form('{% bootstrap_form form %}', context)
def render_form_field(field, context=None):
"""
Create a template that renders a field
"""
form_field = 'form.%s' % field
return render_template_with_form('{% bootstrap_field ' + form_field + ' %}', context)
def render_field(field, context=None):
"""
Create a template that renders a field
"""
if not context:
context = {}
context['field'] = field
return render_template_with_form('{% bootstrap_field field %}', context)
def get_title_from_html(html):
class GetTitleParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.title = None
def handle_starttag(self, tag, attrs):
for attr, value in attrs:
if attr == 'title':
self.title = value
parser = GetTitleParser()
parser.feed(html)
return parser.title
class SettingsTest(TestCase):
def test_settings(self):
from .bootstrap import BOOTSTRAP4
self.assertTrue(BOOTSTRAP4)
# def test_jquery_javascript_tag(self):
# res = render_template_with_form('{% bootstrap_javascript %}')
# self.assertIn(
# '<script src="//code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha384-A7FZj7v+d/sdmMqp/nOQwliLvUsJfDHW+k9Omg/a/EheAdgtzNs3hpfag6Ed950n" crossorigin="anonymous"></script>',
# res.strip()
# )
def test_tether_javascript_tag(self):
res = render_template_with_form('{% bootstrap_javascript %}')
self.assertIn(
'<script crossorigin="anonymous" integrity="sha384-DztdAPBWPRXSA/3eYEEUWrWCy7G5KFbe8fFjk5JAIxUYHKkDx6Qin1DkWx51bBrb" src="//cdnjs.cloudflare.com/ajax/libs/tether/1.4.0/js/tether.min.js"></script>',
res.strip()
)
def test_bootstrap_javascript_tag(self):
res = render_template_with_form('{% bootstrap_javascript %}')
self.assertIn(
'<script crossorigin="anonymous" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" src="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/js/bootstrap.min.js"></script>',
res.strip()
)
def test_bootstrap_css_tag(self):
res = render_template_with_form('{% bootstrap_css %}')
self.assertIn(res.strip(), [
'<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">',
'<link crossorigin="anonymous" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" rel="stylesheet">',
'<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">',
'<link href="//maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">'
])
def test_settings_filter(self):
res = render_template_with_form('{{ "required_css_class"|bootstrap_setting }}')
self.assertEqual(res.strip(), 'bootstrap4-req')
res = render_template_with_form('{% if "javascript_in_head"|bootstrap_setting %}head{% else %}body{% endif %}')
self.assertEqual(res.strip(), 'head')
def test_required_class(self):
form = TestForm()
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap4-req', res)
def test_error_class(self):
form = TestForm({})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap4-err', res)
def test_bound_class(self):
form = TestForm({'sender': 'sender'})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap4-bound', res)
class TemplateTest(TestCase):
def test_empty_template(self):
res = render_template_with_form('')
self.assertEqual(res.strip(), '')
def test_text_template(self):
res = render_template_with_form('some text')
self.assertEqual(res.strip(), 'some text')
def test_bootstrap_template(self):
res = render_template(
'{% extends "bootstrap4/bootstrap4.html" %}' +
'{% block bootstrap4_content %}' +
'test_bootstrap4_content' +
'{% endblock %}'
)
self.assertIn('test_bootstrap4_content', res)
def test_javascript_without_jquery(self):
res = render_template_with_form('{% bootstrap_javascript jquery=0 %}')
self.assertIn('bootstrap', res)
self.assertNotIn('jquery', res)
def test_javascript_with_jquery(self):
res = render_template_with_form('{% bootstrap_javascript jquery=1 %}')
self.assertIn('bootstrap', res)
self.assertIn('jquery', res)
class FormSetTest(TestCase):
def test_illegal_formset(self):
with self.assertRaises(BootstrapError):
render_formset(formset='illegal')
class FormTest(TestCase):
def test_illegal_form(self):
with self.assertRaises(BootstrapError):
render_form(form='illegal')
def test_field_names(self):
form = TestForm()
res = render_form(form)
for field in form:
# datetime has a multiwidget field widget
if field.name == "datetime":
self.assertIn('name="datetime_0"', res)
self.assertIn('name="datetime_1"', res)
else:
self.assertIn('name="%s"' % field.name, res)
def test_field_addons(self):
form = TestForm()
res = render_form(form)
self.assertIn('<div class="input-group"><span class="input-group-addon">before</span><input', res)
self.assertIn('/><span class="input-group-addon">after</span></div>', res)
def test_exclude(self):
form = TestForm()
res = render_template_with_form(
'{% bootstrap_form form exclude="cc_myself" %}', {'form': form})
self.assertNotIn('cc_myself', res)
def test_layout_horizontal(self):
form = TestForm()
res = render_template_with_form(
'{% bootstrap_form form layout="horizontal" %}', {'form': form})
self.assertIn('col-md-3', res)
self.assertIn('col-md-9', res)
res = render_template_with_form(
'{% bootstrap_form form layout="horizontal" ' +
'horizontal_label_class="hlabel" ' +
'horizontal_field_class="hfield" %}',
{'form': form}
)
self.assertIn('hlabel', res)
self.assertIn('hfield', res)
def test_buttons_tag(self):
form = TestForm()
res = render_template_with_form(
'{% buttons layout="horizontal" %}{% endbuttons %}', {'form': form})
self.assertIn('col-md-3', res)
self.assertIn('col-md-9', res)
def test_error_class(self):
form = TestForm({'sender': 'sender'})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap4-err', res)
res = render_template_with_form(
'{% bootstrap_form form error_css_class="successful-test" %}',
{'form': form}
)
self.assertIn('successful-test', res)
res = render_template_with_form('{% bootstrap_form form error_css_class="" %}',
{'form': form})
self.assertNotIn('bootstrap4-err', res)
def test_required_class(self):
form = TestForm({'sender': 'sender'})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap4-req', res)
res = render_template_with_form(
'{% bootstrap_form form required_css_class="successful-test" %}',
{'form': form}
)
self.assertIn('successful-test', res)
res = render_template_with_form('{% bootstrap_form form required_css_class="" %}',
{'form': form})
self.assertNotIn('bootstrap4-req', res)
def test_bound_class(self):
form = TestForm({'sender': 'sender'})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap4-bound', res)
res = render_template_with_form(
'{% bootstrap_form form bound_css_class="successful-test" %}',
{'form': form}
)
self.assertIn('successful-test', res)
res = render_template_with_form(
'{% bootstrap_form form bound_css_class="" %}',
{'form': form}
)
self.assertNotIn('bootstrap4-bound', res)
class FieldTest(TestCase):
def test_illegal_field(self):
with self.assertRaises(BootstrapError):
render_field(field='illegal')
def test_show_help(self):
res = render_form_field('subject')
self.assertIn('my_help_text', res)
self.assertNotIn('<i>my_help_text</i>', res)
res = render_template_with_form('{% bootstrap_field form.subject show_help=0 %}')
self.assertNotIn('my_help_text', res)
def test_help_with_quotes(self):
# Checkboxes get special handling, so test a checkbox and something else
res = render_form_field('sender')
self.assertEqual(get_title_from_html(res), TestForm.base_fields['sender'].help_text)
res = render_form_field('cc_myself')
self.assertEqual(get_title_from_html(res), TestForm.base_fields['cc_myself'].help_text)
def test_subject(self):
res = render_form_field('subject')
self.assertIn('type="text"', res)
self.assertIn('placeholder="placeholdertest"', res)
def test_password(self):
res = render_form_field('password')
self.assertIn('type="password"', res)
self.assertIn('placeholder="Password"', res)
def test_required_field(self):
"""
Does a required field get the CSS class for required?
"""
required_css_class='bootstrap4-req'
required_field = render_form_field('subject')
self.assertIn(required_css_class, required_field)
not_required_field = render_form_field('message')
self.assertNotIn(required_css_class, not_required_field)
# Required settings in field
form_field = 'form.subject'
rendered = render_template_with_form(
'{% bootstrap_field ' + form_field + ' required_css_class="test-required" %}')
self.assertIn('test-required', rendered)
def test_empty_permitted(self):
"""
If a form has empty_permitted, no fields should get the CSS class for required
"""
required_css_class='bootstrap4-req'
form = TestForm()
res = render_form_field('subject', {'form': form})
self.assertIn(required_css_class, res)
form.empty_permitted = True
res = render_form_field('subject', {'form': form})
self.assertNotIn(required_css_class, res)
def test_input_group(self):
res = render_template_with_form('{% bootstrap_field form.subject addon_before="$" addon_after=".00" %}')
self.assertIn('class="input-group"', res)
self.assertIn('class="input-group-addon">$', res)
self.assertIn('class="input-group-addon">.00', res)
def test_input_group_addon_button(self):
res = render_template_with_form('{% bootstrap_field form.subject addon_before="$" addon_before_class="input-group-btn" addon_after=".00" addon_after_class="input-group-btn" %}')
self.assertIn('class="input-group"', res)
self.assertIn('class="input-group-btn">$', res)
self.assertIn('class="input-group-btn">.00', res)
def test_size(self):
def _test_size(param, klass):
res = render_template_with_form('{% bootstrap_field form.subject size="' + param + '" %}')
self.assertIn(klass, res)
def _test_size_medium(param):
res = render_template_with_form('{% bootstrap_field form.subject size="' + param + '" %}')
self.assertNotIn('input-lg', res)
self.assertNotIn('input-sm', res)
self.assertNotIn('input-md', res)
_test_size('sm', 'input-sm')
_test_size('small', 'input-sm')
_test_size('lg', 'input-lg')
_test_size('large', 'input-lg')
_test_size_medium('md')
_test_size_medium('medium')
_test_size_medium('')
def test_datetime(self):
field = render_form_field('datetime')
self.assertIn('vDateField', field)
self.assertIn('vTimeField', field)
def test_field_same_render(self):
context = dict(form=TestForm())
rendered_a = render_form_field("addon", context)
rendered_b = render_form_field("addon", context)
self.assertEqual(rendered_a, rendered_b)
def test_label(self):
res = render_template_with_form('{% bootstrap_label "foobar" label_for="subject" %}')
self.assertEqual('<label for="subject">foobar</label>', res)
def test_attributes_consistency(self):
form = TestForm()
attrs = form.fields['addon'].widget.attrs.copy()
context = dict(form=form)
field_alone = render_form_field("addon", context)
self.assertEqual(attrs, form.fields['addon'].widget.attrs)
class ComponentsTest(TestCase):
# TODO change it to the new icons
# def test_icon(self):
# res = render_template_with_form('{% bootstrap_icon "star" %}')
# self.assertEqual(
# res.strip(), '<span class="glyphicon glyphicon-star"></span>')
# res = render_template_with_form('{% bootstrap_icon "star" title="alpha centauri" %}')
# self.assertIn(res.strip(), [
# '<span class="glyphicon glyphicon-star" title="alpha centauri"></span>',
# '<span title="alpha centauri" class="glyphicon glyphicon-star"></span>',
# ])
def test_alert(self):
res = render_template_with_form('{% bootstrap_alert "content" alert_type="danger" %}')
self.assertEqual(
res.strip(),
'<div class="alert alert-danger alert-dismissable">' +
'<button type="button" class="close" data-dismiss="alert" ' +
'aria-hidden="true">' +
'×</button>content</div>'
)
class MessagesTest(TestCase):
def test_messages(self):
class FakeMessage(object):
"""
Follows the `django.contrib.messages.storage.base.Message` API.
"""
level = None
message = None
extra_tags = None
def __init__(self, level, message, extra_tags=None):
self.level = level
self.extra_tags = extra_tags
self.message = message
def __str__(self):
return self.message
pattern = re.compile(r'\s+')
messages = [FakeMessage(DEFAULT_MESSAGE_LEVELS.WARNING, "hello")]
res = render_template_with_form(
'{% bootstrap_messages messages %}', {'messages': messages})
expected = """
<div class="alert alert-warning alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
hello
</div>
"""
self.assertEqual(
re.sub(pattern, '', res),
re.sub(pattern, '', expected)
)
messages = [FakeMessage(DEFAULT_MESSAGE_LEVELS.ERROR, "hello")]
res = render_template_with_form(
'{% bootstrap_messages messages %}', {'messages': messages})
expected = """
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
hello
</div>
"""
self.assertEqual(
re.sub(pattern, '', res),
re.sub(pattern, '', expected)
)
messages = [FakeMessage(None, "hello")]
res = render_template_with_form(
'{% bootstrap_messages messages %}', {'messages': messages})
expected = """
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
hello
</div>
"""
self.assertEqual(
re.sub(pattern, '', res),
re.sub(pattern, '', expected)
)
messages = [FakeMessage(DEFAULT_MESSAGE_LEVELS.ERROR, "hello http://example.com")]
res = render_template_with_form(
'{% bootstrap_messages messages %}', {'messages': messages})
expected = """
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
hello http://example.com
</div> """
self.assertEqual(
re.sub(pattern, '', res).replace('rel="nofollow"', ''),
re.sub(pattern, '', expected).replace('rel="nofollow"', '')
)
messages = [FakeMessage(DEFAULT_MESSAGE_LEVELS.ERROR, "hello\nthere")]
res = render_template_with_form(
'{% bootstrap_messages messages %}', {'messages': messages})
expected = """
<div class="alert alert-danger alert-dismissable">
<button type="button" class="close" data-dismiss="alert"
aria-hidden="true">×</button>
hello there
</div>
"""
self.assertEqual(
re.sub(pattern, '', res),
re.sub(pattern, '', expected)
)
class UtilsTest(TestCase):
def test_add_css_class(self):
css_classes = "one two"
css_class = "three four"
classes = add_css_class(css_classes, css_class)
self.assertEqual(classes, "one two three four")
classes = add_css_class(css_classes, css_class, prepend=True)
self.assertEqual(classes, "three four one two")
def test_text_value(self):
self.assertEqual(text_value(''), "")
self.assertEqual(text_value(' '), " ")
self.assertEqual(text_value(None), "")
self.assertEqual(text_value(1), "1")
def test_text_concat(self):
self.assertEqual(text_concat(1, 2), "12")
self.assertEqual(text_concat(1, 2, separator='='), "1=2")
self.assertEqual(text_concat(None, 2, separator='='), "2")
def test_render_tag(self):
self.assertEqual(render_tag('span'), '<span></span>')
self.assertEqual(render_tag('span', content='foo'), '<span>foo</span>')
self.assertEqual(
render_tag('span', attrs={'bar': 123}, content='foo'),
'<span bar="123">foo</span>'
)
class ButtonTest(TestCase):
def test_button(self):
res = render_template_with_form("{% bootstrap_button 'button' size='lg' %}")
self.assertEqual(
res.strip(), '<button class="btn btn-default btn-lg">button</button>')
res = render_template_with_form("{% bootstrap_button 'button' size='lg' href='#' %}")
self.assertIn(
res.strip(),
'<a class="btn btn-default btn-lg" href="#">button</a><a href="#" ' +
'class="btn btn-lg">button</a>')
class ShowLabelTest(TestCase):
def test_show_label(self):
form = TestForm()
res = render_template_with_form(
'{% bootstrap_form form show_label=False %}',
{'form': form}
)
self.assertIn('sr-only', res)
def test_for_formset(self):
TestFormSet = formset_factory(TestForm, extra=1)
test_formset = TestFormSet()
res = render_template_with_form(
'{% bootstrap_formset formset show_label=False %}',
{'formset': test_formset}
)
self.assertIn('sr-only', res)
# TODO change for the new icons
# def test_button_with_icon(self):
# res = render_template_with_form(
# "{% bootstrap_button 'test' icon='info-sign' %}"
# )
# self.assertEqual(
# res.strip(),
# '<button class="btn btn-default"><span class="glyphicon glyphicon-info-sign"></span> test</button>'
# )
# res = render_template_with_form(
# "{% bootstrap_button 'test' icon='info-sign' button_class='btn-primary' %}"
# )
# self.assertEqual(
# res.strip(),
# '<button class="btn btn-primary"><span class="glyphicon glyphicon-info-sign"></span> test</button>'
# )
# res = render_template_with_form(
# "{% bootstrap_button 'test' icon='info-sign' button_type='submit' %}"
# )
# self.assertEqual(
# res.strip(),
# '<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-info-sign"></span> test</button>'