Skip to content

Commit

Permalink
Add ignore_attrs to assertHTMLEqual
Browse files Browse the repository at this point in the history
  • Loading branch information
dyve committed Dec 26, 2023
1 parent 840dab1 commit 462e3fa
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/django_marina/html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from bs4 import BeautifulSoup


def remove_attrs(html, attrs=None):
"""Return html string without the specified tags."""
if html and attrs:
soup = BeautifulSoup(html, "html.parser")
soup = _remove_attrs(soup, attrs)
html = f"{soup}"
return html


def _remove_attrs(soup, attrs):
for attr in attrs:
for tag in soup.findAll(attrs={attr: True}):
del tag.attrs[attr]
return soup
8 changes: 8 additions & 0 deletions tests/test_html.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.test import TestCase

from django_marina.html import remove_attrs


class HtmlTestCase(TestCase):
def test_remove_attrs(self):
self.assertEqual(remove_attrs('<span foo="bar"></span>', ["foo"]), "<span></span>")

0 comments on commit 462e3fa

Please sign in to comment.