Skip to content

Commit

Permalink
Add flake8 test, fix coverage in tox
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed May 24, 2017
1 parent 3c5a675 commit 70bf8cf
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 95 deletions.
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ pip-log.txt
*.log

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.tox
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover

# Translations
*.mo
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2017, Dylan Verheul
Copyright (c) 2017, Dylan Verheul and individual contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
13 changes: 9 additions & 4 deletions bootstrap3/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@

FORM_GROUP_CLASS = 'form-group'

WIDGETS_NO_REQUIRED = (
AdminFileWidget,
HiddenInput,
FileInput,
CheckboxInput,
CheckboxSelectMultiple
)


def render_formset(formset, **kwargs):
"""
Expand Down Expand Up @@ -167,10 +175,7 @@ def is_widget_required_attribute(widget):
return False
if not widget.is_required:
return False
if isinstance(
widget, (
AdminFileWidget, HiddenInput, FileInput,
CheckboxInput, CheckboxSelectMultiple)):
if isinstance(widget, WIDGETS_NO_REQUIRED):
return False
return True

Expand Down
8 changes: 4 additions & 4 deletions bootstrap3/templatetags/bootstrap3.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,20 +451,20 @@ def bootstrap_field(*args, **kwargs):
addon_before
Text that should be prepended to the form field. Can also be an icon, e.g.
``'<span class="glyphicon glyphicon-calendar"></span>'``
See the `Bootstrap docs <http://getbootstrap.com/components/#input-groups-basic>` for more examples.
addon_after
Text that should be appended to the form field. Can also be an icon, e.g.
``'<span class="glyphicon glyphicon-calendar"></span>'``
See the `Bootstrap docs <http://getbootstrap.com/components/#input-groups-basic>` for more examples.
addon_before_class
Class used on the span when ``addon_before`` is used.
One of the following values:
* ``'input-group-addon'``
* ``'input-group-btn'``
Expand All @@ -474,7 +474,7 @@ def bootstrap_field(*args, **kwargs):
Class used on the span when ``addon_after`` is used.
One of the following values:
* ``'input-group-addon'``
* ``'input-group-btn'``
Expand Down
23 changes: 11 additions & 12 deletions bootstrap3/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

from django import forms
from django.contrib.admin.widgets import AdminSplitDateTime
from django.contrib.gis import forms as gisforms
from django.contrib.messages import constants as DEFAULT_MESSAGE_LEVELS
from django.forms.formsets import formset_factory
from django.template import engines
Expand All @@ -30,13 +29,11 @@
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
)),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
)),
('unknown', 'Unknown'),
)

Expand Down Expand Up @@ -466,7 +463,7 @@ def test_input_group(self):

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" %}')
'{% bootstrap_field form.subject addon_before="$" addon_before_class="input-group-btn" addon_after=".00" addon_after_class="input-group-btn" %}') # noqa
self.assertIn('class="input-group"', res)
self.assertIn('class="input-group-btn">$', res)
self.assertIn('class="input-group-btn">.00', res)
Expand Down Expand Up @@ -508,8 +505,6 @@ def test_label(self):
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)


Expand Down Expand Up @@ -707,9 +702,14 @@ def test_button_with_icon(self):
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>'
self.assertHTMLEqual(
res,
'<button'
' class="btn btn-default"'
' type="submit">'
'<span'
' class="glyphicon glyphicon-info-sign"></span>'
' test</button>'
)


Expand All @@ -720,7 +720,6 @@ def test_placeholder_set_from_label(self):


class ShowAddonsTest(TestCase):

def assertFieldHasAddons(self, field):
"""Asserts that a given field has an after and before addon."""
addon_before = "bf"
Expand Down
8 changes: 3 additions & 5 deletions demo/demo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from django import forms
from django.forms.formsets import BaseFormSet, formset_factory


from bootstrap3.tests import TestForm

RADIO_CHOICES = (
Expand All @@ -16,13 +15,11 @@
('Audio', (
('vinyl', 'Vinyl'),
('cd', 'CD'),
)
),
)),
('Video', (
('vhs', 'VHS Tape'),
('dvd', 'DVD'),
)
),
)),
('unknown', 'Unknown'),
)

Expand All @@ -39,6 +36,7 @@ def clean(self):
super(ContactBaseFormSet, self).clean()
raise forms.ValidationError("This error was added to show the non form errors styling")


ContactFormSet = formset_factory(TestForm, formset=ContactBaseFormSet,
extra=2,
max_num=4,
Expand Down
4 changes: 3 additions & 1 deletion demo/demo/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"""
import os

from django.core.wsgi import get_wsgi_application

# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
Expand All @@ -24,7 +26,7 @@
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application

application = get_wsgi_application()

# Apply WSGI middleware here.
Expand Down
Loading

0 comments on commit 70bf8cf

Please sign in to comment.