From f3e492b20c05aba2d51fa9806dc1708dc19045dd Mon Sep 17 00:00:00 2001 From: Parbhat Puri Date: Fri, 3 Apr 2020 21:54:14 +0530 Subject: [PATCH] Tests for SnippetEmbedHandler --- ...nk_handler.py => test_snippet_handlers.py} | 28 ++++++++++++++++++- .../testapp/advert_snippet_embed.html | 1 + ..._snippet.html => advert_snippet_link.html} | 0 3 files changed, 28 insertions(+), 1 deletion(-) rename tests/{test_snippet_link_handler.py => test_snippet_handlers.py} (51%) create mode 100644 tests/testapp/templates/testapp/advert_snippet_embed.html rename tests/testapp/templates/testapp/{advert_snippet.html => advert_snippet_link.html} (100%) 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