Skip to content

Commit

Permalink
Test for no registered snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
mgax committed Sep 24, 2024
1 parent 09ea03b commit 4cb019a
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions tests/test_grapple.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from wagtail.models import Page, Site
from wagtailmedia.models import get_media_model

from grapple.registry import RegistryItem
from grapple.schema import create_schema


Expand Down Expand Up @@ -1606,3 +1607,25 @@ def test_snippets(self):
snippets_data = executed["data"]["snippets"]
self.assertEqual(snippets_data[0]["snippetType"], "Advert")
self.assertEqual(snippets_data[0]["contentType"], "testapp.Advert")

def test_no_snippet_classes_registered(self):
"""
If there are no registered snippet classes, the snippets query should
still work, and return nothing.
"""

query = """
{
snippets {
snippetType
contentType
}
}
"""

with patch("grapple.registry.registry.snippets", RegistryItem()):
executed = self.client.execute(query)

self.assertEqual(type(executed["data"]), dict)
self.assertEqual(type(executed["data"]["snippets"]), list)
self.assertEqual(len(executed["data"]["snippets"]), 0)

0 comments on commit 4cb019a

Please sign in to comment.