Skip to content

Commit

Permalink
Fix GitHub Actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Dec 24, 2023
1 parent 1a03c37 commit 3c562db
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 66 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ tests:

.PHONY: reformat
reformat:
ruff --fix .
ruff format .
ruff --fix .

.PHONY: lint
lint:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bootstrap_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def test_placeholder(self):
self.assertIn('placeholder="placeholdertest"', html)

def test_field_class(self):
html = self.render("{% bootstrap_field form.subject field_class='field-class-test' %}", {"form": SubjectTestForm()})
html = self.render(
"{% bootstrap_field form.subject field_class='field-class-test' %}", {"form": SubjectTestForm()}
)
self.assertIn('class="form-control field-class-test"', html)

def test_xss_field(self):
Expand Down
4 changes: 1 addition & 3 deletions tests/test_bootstrap_field_input_checkbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class InputTypeCheckboxTestCase(BootstrapTestCase):
def test_input_type_checkbox(self):
"""Test field with checkbox widget."""
self.assertHTMLEqual(
self.render(
"{% bootstrap_field form.test %}", context={"form": CheckboxTestForm()}
),
self.render("{% bootstrap_field form.test %}", context={"form": CheckboxTestForm()}),
(
'<div class="django_bootstrap5-req mb-3">'
'<div class="form-check">'
Expand Down
64 changes: 33 additions & 31 deletions tests/test_bootstrap_field_input_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,21 +146,23 @@ def test_input_type_text_more(self):
),
)

self.assertHTMLEqual(
self.render(
"{% bootstrap_field form.test layout='horizontal' %}",
context={"form": form},
(
self.assertHTMLEqual(
self.render(
"{% bootstrap_field form.test layout='horizontal' %}",
context={"form": form},
),
(
'<div class="django_bootstrap5-req mb-3 row">'
'<label class="col-form-label col-sm-2" for="id_test">'
"Test"
'</label><div class="col-sm-10">'
'<input class="form-control" id="id_test" name="test" placeholder="Test" required type="text">'
"</div>"
"</div>"
),
),
(
'<div class="django_bootstrap5-req mb-3 row">'
'<label class="col-form-label col-sm-2" for="id_test">'
"Test"
'</label><div class="col-sm-10">'
'<input class="form-control" id="id_test" name="test" placeholder="Test" required type="text">'
"</div>"
"</div>"
),
),
)

self.assertHTMLEqual(
self.render(
Expand All @@ -180,9 +182,7 @@ def test_input_validation_failure(self):
form = CharFieldRequiredTestForm(data={"test": ""})
self.assertFalse(form.is_valid())

html = self.render(
'{% bootstrap_field form.test addon_before="foo" %}', context={"form": form}
)
html = self.render('{% bootstrap_field form.test addon_before="foo" %}', context={"form": form})
if DJANGO_VERSION >= "5":
html = html.replace(' aria-invalid="true"', "")

Expand Down Expand Up @@ -301,21 +301,23 @@ class PasswordTestForm(forms.Form):
),
)

self.assertHTMLEqual(
self.render(
"{% bootstrap_field form.test layout='horizontal' %}",
context={"form": form},
),
(
'<div class="django_bootstrap5-req mb-3 row">'
'<label class="col-form-label col-sm-2" for="id_test">'
"Test"
'</label><div class="col-sm-10">'
'<input class="form-control" id="id_test" name="test" placeholder="Test" required type="password">'
"</div>"
"</div>"
(
self.assertHTMLEqual(
self.render(
"{% bootstrap_field form.test layout='horizontal' %}",
context={"form": form},
),
(
'<div class="django_bootstrap5-req mb-3 row">'
'<label class="col-form-label col-sm-2" for="id_test">'
"Test"
'</label><div class="col-sm-10">'
'<input class="form-control" id="id_test" name="test" placeholder="Test" required type="password">'
"</div>"
"</div>"
),
),
),
)

self.assertHTMLEqual(
self.render(
Expand Down
40 changes: 10 additions & 30 deletions tests/test_bootstrap_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@


class FormTestForm(forms.Form):
required_text = forms.CharField(
required=True, help_text="<i>required_text_help</i>"
)
optional_text = forms.CharField(
required=False, help_text="<i>required_text_help</i>"
)
required_text = forms.CharField(required=True, help_text="<i>required_text_help</i>")
optional_text = forms.CharField(required=False, help_text="<i>required_text_help</i>")


class ShowLabelTestForm(forms.Form):
Expand Down Expand Up @@ -66,9 +62,7 @@ def test_error_css_class(self):
)
self.assertIn("custom-error-class", html)

html = self.render(
'{% bootstrap_form form error_css_class="" %}', {"form": form}
)
html = self.render('{% bootstrap_form form error_css_class="" %}', {"form": form})
self.assertNotIn("django_bootstrap5-err", html)

def test_required_css_class(self):
Expand All @@ -82,9 +76,7 @@ def test_required_css_class(self):
)
self.assertIn("custom-required-class", html)

html = self.render(
'{% bootstrap_form form required_css_class="" %}', {"form": form}
)
html = self.render('{% bootstrap_form form required_css_class="" %}', {"form": form})
self.assertNotIn("django_bootstrap5-req", html)

def test_success_css_class(self):
Expand All @@ -103,25 +95,19 @@ def test_success_css_class(self):

form = FormTestForm({"subject": "subject"})

html = self.render(
'{% bootstrap_form form success_css_class="" %}', {"form": form}
)
html = self.render('{% bootstrap_form form success_css_class="" %}', {"form": form})
self.assertNotIn("django_bootstrap5-success", html)

def test_alert_error_type(self):
form = NonFieldErrorTestForm({"subject": "subject"})

html = self.render(
"{% bootstrap_form form alert_error_type='all' %}", {"form": form}
)
html = self.render("{% bootstrap_form form alert_error_type='all' %}", {"form": form})
soup = BeautifulSoup(html, "html.parser")
errors = list(soup.select(".text-danger")[0].stripped_strings)
self.assertIn(form.non_field_error_message, errors)
self.assertIn("This field is required.", errors)

html = self.render(
"{% bootstrap_form form alert_error_type='non_fields' %}", {"form": form}
)
html = self.render("{% bootstrap_form form alert_error_type='non_fields' %}", {"form": form})
self.assertEqual(
html,
self.render("{% bootstrap_form form %}", {"form": form}),
Expand All @@ -133,17 +119,13 @@ def test_alert_error_type(self):
self.assertIn(form.non_field_error_message, errors)
self.assertNotIn("This field is required.", errors)

html = self.render(
"{% bootstrap_form form alert_error_type='fields' %}", {"form": form}
)
html = self.render("{% bootstrap_form form alert_error_type='fields' %}", {"form": form})
soup = BeautifulSoup(html, "html.parser")
errors = list(soup.select(".text-danger")[0].stripped_strings)
self.assertNotIn(form.non_field_error_message, errors)
self.assertIn("This field is required.", errors)

html = self.render(
"{% bootstrap_form form alert_error_type='none' %}", {"form": form}
)
html = self.render("{% bootstrap_form form alert_error_type='none' %}", {"form": form})
soup = BeautifulSoup(html, "html.parser")
self.assertFalse(soup.select(".text-danger"))

Expand All @@ -169,9 +151,7 @@ def test_show_label_false(self):
def test_show_label_sr_only(self):
self.assertInHTML(
'<label class="visually-hidden" for="id_subject">Subject</label>',
self.render(
"{% bootstrap_form form show_label='' %}", {"form": ShowLabelTestForm()}
),
self.render("{% bootstrap_form form show_label='' %}", {"form": ShowLabelTestForm()}),
)

def test_show_label_skip(self):
Expand Down

0 comments on commit 3c562db

Please sign in to comment.