diff --git a/tests/test_snippet_link_handler.py b/tests/test_snippet_handlers.py similarity index 51% rename from tests/test_snippet_link_handler.py rename to tests/test_snippet_handlers.py index efa7d84..dbcea45 100644 --- a/tests/test_snippet_link_handler.py +++ b/tests/test_snippet_handlers.py @@ -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'' + + +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'
{advert.text}
' diff --git a/tests/testapp/templates/testapp/advert_snippet_embed.html b/tests/testapp/templates/testapp/advert_snippet_embed.html new file mode 100644 index 0000000..e2264b7 --- /dev/null +++ b/tests/testapp/templates/testapp/advert_snippet_embed.html @@ -0,0 +1 @@ +
{{ object.text }}
\ No newline at end of file diff --git a/tests/testapp/templates/testapp/advert_snippet.html b/tests/testapp/templates/testapp/advert_snippet_link.html similarity index 100% rename from tests/testapp/templates/testapp/advert_snippet.html rename to tests/testapp/templates/testapp/advert_snippet_link.html