-
-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle component templates with comments or blank strings before a ro…
…ot element.
- Loading branch information
Showing
4 changed files
with
70 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
<!-- test comment --> | ||
|
||
<div> | ||
<div> | ||
<label>Dictionaries (original)</label> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import pytest | ||
from bs4 import BeautifulSoup | ||
|
||
from django_unicorn.components.unicorn_template_response import get_root_element | ||
|
||
|
||
def test_get_root_element(): | ||
expected = "<div>test</div>" | ||
|
||
component_html = "<div>test</div>" | ||
soup = BeautifulSoup(component_html, features="html.parser") | ||
actual = get_root_element(soup) | ||
|
||
assert str(actual) == expected | ||
|
||
|
||
def test_get_root_element_with_comment(): | ||
expected = "<div>test</div>" | ||
|
||
component_html = "<!-- some comment --><div>test</div>" | ||
soup = BeautifulSoup(component_html, features="html.parser") | ||
actual = get_root_element(soup) | ||
|
||
assert str(actual) == expected | ||
|
||
|
||
def test_get_root_element_with_blank_string(): | ||
expected = "<div>test</div>" | ||
|
||
component_html = "\n<div>test</div>" | ||
soup = BeautifulSoup(component_html, features="html.parser") | ||
actual = get_root_element(soup) | ||
|
||
assert str(actual) == expected | ||
|
||
|
||
def test_get_root_element_no_element(): | ||
expected = "<div>test</div>" | ||
|
||
component_html = "\n" | ||
soup = BeautifulSoup(component_html, features="html.parser") | ||
|
||
with pytest.raises(Exception): | ||
actual = get_root_element(soup) | ||
|
||
assert str(actual) == expected |