Skip to content

Commit

Permalink
Fix bug with theme url, add test (fix #359)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Jan 24, 2017
1 parent 8577582 commit a6050a6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
2 changes: 1 addition & 1 deletion bootstrap3/templatetags/bootstrap3.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def bootstrap_css():
"""
rendered_urls = [render_link_tag(bootstrap_css_url()), ]
if bootstrap_theme_url():
rendered_urls.append(render_link_tag(bootstrap_css_url()))
rendered_urls.append(render_link_tag(bootstrap_theme_url()))
return mark_safe(''.join([url for url in rendered_urls]))


Expand Down
52 changes: 29 additions & 23 deletions bootstrap3/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
)



class TestForm(forms.Form):
"""
Form with a variety of widgets to test bootstrap3 rendering.
Expand Down Expand Up @@ -207,33 +206,40 @@ def test_bootstrap_javascript_tag(self):
)

def test_bootstrap_css_tag(self):
self.maxDiff = None
res = render_template_with_form('{% bootstrap_css %}')
self.assertEqual(
res.strip(),
'<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">'
res = render_template_with_form('{% bootstrap_css %}').strip()
self.assertIn(
'<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">',
res
)
self.assertIn(
'<link href="//example.com/theme.css" rel="stylesheet">',
res
)

def test_settings_filter(self):
res = render_template_with_form('{{ "required_css_class"|bootstrap_setting }}')
self.assertEqual(res.strip(), 'bootstrap3-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('bootstrap3-req', res)
def test_settings_filter(self):
res = render_template_with_form('{{ "required_css_class"|bootstrap_setting }}')
self.assertEqual(res.strip(), 'bootstrap3-req')
res = render_template_with_form('{% if "javascript_in_head"|bootstrap_setting %}head{% else %}body{% endif %}')
self.assertEqual(res.strip(), 'head')

def test_error_class(self):
form = TestForm({})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap3-err', res)

def test_bound_class(self):
form = TestForm({'sender': 'sender'})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap3-bound', res)
def test_required_class(self):
form = TestForm()
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap3-req', res)


def test_error_class(self):
form = TestForm({})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap3-err', res)


def test_bound_class(self):
form = TestForm({'sender': 'sender'})
res = render_template_with_form('{% bootstrap_form form %}', {'form': form})
self.assertIn('bootstrap3-bound', res)


class TemplateTest(TestCase):
Expand Down
1 change: 1 addition & 0 deletions testsettings.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
ROOT_URLCONF = None

BOOTSTRAP3 = {
'theme_url': '//example.com/theme.css',
'javascript_in_head': True,
'required_css_class': 'bootstrap3-req',
'error_css_class': 'bootstrap3-err',
Expand Down

0 comments on commit a6050a6

Please sign in to comment.