1
Fork 0

Tests for SnippetEmbedHandler

This commit is contained in:
Parbhat Puri 2020-04-03 21:54:14 +05:30
parent a30c737920
commit f3e492b20c
3 changed files with 28 additions and 1 deletions

View file

@ -1,5 +1,5 @@
import pytest
from wagtail_draftail_snippet.richtext import SnippetLinkHandler
from wagtail_draftail_snippet.richtext import SnippetLinkHandler, SnippetEmbedHandler
class TestSnippetLinkHandler:
@ -26,3 +26,29 @@ class TestSnippetLinkHandler:
attrs = {"id": 1, "data-app-name": "testapp", "data-model-name": "Advert"}
result = SnippetLinkHandler.expand_db_attributes(attrs)
assert result == f'<a href="{advert.url}/{advert.id}">'
class TestSnippetEmbedHandler:
@pytest.mark.django_db
def test_advert_setup_correctly(self, advert):
assert advert.text == "advert"
assert advert.url == "https://www.example.com"
@pytest.mark.django_db
def test_snippet_create_empty_block_on_error(self, advert):
"""
Empty block created in case of exception
"""
result = SnippetEmbedHandler.expand_db_attributes({"id": 0})
assert result == ""
@pytest.mark.django_db
def test_snippet_embed_handler_renders(self, advert):
"""
Test snippet template renders correctly
"""
attrs = {"id": 1, "data-app-name": "testapp", "data-model-name": "Advert"}
result = SnippetEmbedHandler.expand_db_attributes(attrs)
assert result == f'<div>{advert.text}</div>'

View file

@ -0,0 +1 @@
<div>{{ object.text }}</div>