added assets_formatter and remove_formatter
This commit is contained in:
1 parent
8697f3ecb5
commit
ddc9add551
6 files changed
+108
-7
No files matched your search
@@ -0,0 +1,31 @@
|
||||
from unittest import TestCase
|
||||
from bs4 import BeautifulSoup
|
||||
from html_to_django.formatters import assets_formatter
|
||||
|
||||
|
||||
class AssetsTests(TestCase):
|
||||
def test_basic(self) -> None:
|
||||
soup = BeautifulSoup('<html dj-assets="assets;module"><img src="assets/image.png"></html>', 'html.parser')
|
||||
assets_formatter.format(soup)
|
||||
expected_result = '<html><img src="{% static \'module/assets/image.png\' %}"/></html>'
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_empty(self) -> None:
|
||||
soup = BeautifulSoup('<html dj-assets="assets;module"></html>', 'html.parser')
|
||||
assets_formatter.format(soup)
|
||||
expected_result = '<html></html>'
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_no_assets(self) -> None:
|
||||
soup = BeautifulSoup('<html dj-assets="assets;module"><p>Test</p></html>', 'html.parser')
|
||||
assets_formatter.format(soup)
|
||||
expected_result = '<html><p>Test</p></html>'
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_with_multiple_assets(self) -> None:
|
||||
soup = BeautifulSoup('<html dj-assets="assets;module"><img src="assets/image1.png"><img '
|
||||
'src="assets/image2.png"></html>', 'html.parser')
|
||||
assets_formatter.format(soup)
|
||||
expected_result = ('<html><img src="{% static \'module/assets/image1.png\' %}"/><img src="{% static '
|
||||
'\'module/assets/image2.png\' %}"/></html>')
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
@@ -0,0 +1,23 @@
|
||||
from unittest import TestCase
|
||||
from bs4 import BeautifulSoup
|
||||
from html_to_django.formatters import remove_formatter
|
||||
|
||||
|
||||
class RemoveTests(TestCase):
|
||||
def test_basic(self) -> None:
|
||||
soup = BeautifulSoup('<div dj-remove><div>Test</div></div>', "html.parser")
|
||||
remove_formatter.format(soup)
|
||||
expected_result = ""
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_empty(self) -> None:
|
||||
soup = BeautifulSoup('<div dj-remove></div>', "html.parser")
|
||||
remove_formatter.format(soup)
|
||||
expected_result = ""
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_with_remove_inside(self) -> None:
|
||||
soup = BeautifulSoup('<div dj-remove><div dj-remove>Inner Test</div></div>', "html.parser")
|
||||
remove_formatter.format(soup)
|
||||
expected_result = ""
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
@@ -5,19 +5,19 @@ from html_to_django.formatters import unwrap_formatter
|
||||
|
||||
class UnwrapTests(TestCase):
|
||||
def test_basic(self) -> None:
|
||||
soup = BeautifulSoup('<div dj-unwrap="true"><div>Test</div></div>', "html.parser")
|
||||
soup = BeautifulSoup('<div dj-unwrap><div>Test</div></div>', "html.parser")
|
||||
unwrap_formatter.format(soup)
|
||||
expected_result = "<div>Test</div>"
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_empty(self) -> None:
|
||||
soup = BeautifulSoup('<div dj-unwrap="true"></div>', "html.parser")
|
||||
soup = BeautifulSoup('<div dj-unwrap></div>', "html.parser")
|
||||
unwrap_formatter.format(soup)
|
||||
expected_result = ""
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
|
||||
def test_with_unwrap_inside(self) -> None:
|
||||
soup = BeautifulSoup('<div dj-unwrap="true"><div dj-unwrap="true">Inner Test</div></div>', "html.parser")
|
||||
soup = BeautifulSoup('<div dj-unwrap><div dj-unwrap>Inner Test</div></div>', "html.parser")
|
||||
unwrap_formatter.format(soup)
|
||||
expected_result = "Inner Test"
|
||||
self.assertEqual(expected_result, str(soup))
|
||||
Reference in new issue
Block a user