1
Fork 0
This repository has been archived on 2024-07-16. You can view files and clone it, but cannot push or open issues or pull requests.
wagtail-draftail-snippet/tests/test_snippet_handlers.py

55 lines
1.7 KiB
Python
Raw Normal View History

2020-02-13 12:23:35 +00:00
import pytest
2020-04-03 17:24:14 +01:00
from wagtail_draftail_snippet.richtext import SnippetLinkHandler, SnippetEmbedHandler
2020-02-13 12:23:35 +00:00
2020-02-15 03:23:14 +00:00
class TestSnippetLinkHandler:
@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_link_on_error(self, advert):
"""
Empty link created in case of exception
"""
2020-02-13 12:23:35 +00:00
2020-02-15 03:23:14 +00:00
result = SnippetLinkHandler.expand_db_attributes({"id": 0})
assert result == "<a>"
2020-02-13 12:23:35 +00:00
2020-02-15 03:23:14 +00:00
@pytest.mark.django_db
def test_snippet_link_handler_renders(self, advert):
"""
Test snippet template renders correctly
"""
2020-02-13 12:23:35 +00:00
attrs = {"id": 1, "data-app-name": "testapp", "data-model-name": "advert"}
2020-02-15 03:23:14 +00:00
result = SnippetLinkHandler.expand_db_attributes(attrs)
assert result == f'<a href="{advert.url}/{advert.id}">'
2020-04-03 17:24:14 +01:00
class TestSnippetEmbedHandler:
@pytest.mark.django_db
def test_advert_setup_correctly(self, advert):
assert advert.text == "advert"
assert advert.url == "https://www.example.com"
2020-04-08 07:24:26 +01:00
@pytest.mark.django_db
def test_snippet_create_empty_block_on_error(self, advert):
"""
Empty block created in case of exception
"""
2020-04-08 07:24:26 +01:00
result = SnippetEmbedHandler.expand_db_attributes({"id": 0})
assert result == ""
2020-04-08 07:24:26 +01:00
@pytest.mark.django_db
def test_snippet_embed_handler_renders(self, advert):
"""
Test snippet template renders correctly
"""
2020-04-08 07:24:26 +01:00
attrs = {"id": 1, "data-app-name": "testapp", "data-model-name": "advert"}
result = SnippetEmbedHandler.expand_db_attributes(attrs)
assert result == f'<div>{advert.text}</div>'