Repository: wagtail/wagtail
File: wagtail/snippets/tests/test_viewset.py (Python)

Code before:
    def test_unknown_converter(self):
        class BadViewSet(SnippetViewSet):
            model = AdvertTag
            url_converter = "foo"

        with self.assertRaises(ImproperlyConfigured) as cm:
            register_snippet(BadViewSet)
        message = str(cm.exception)
        self.assertEqual(
            "BadViewSet is using an unknown URL converter",
            message,
        )


class TestSnippetConverter(TestCase):
    def setUp(self):
        super().setUp()
        self.viewset = AdvertWithCustomUUIDPrimaryKey.snippet_viewset

    def test_cannot_reverse(self):
        edit_url = f"{self.viewset.url_namespace}:edit"
        with self.assertRaises(NoReverseMatch):
            reverse(edit_url, kwargs={"pk": 123})

    def test_404_on_pk_not_uuids(self):
        response = self.client.get(f"{self.viewset.url_prefix}/edit/123/")
        self.assertEqual(response.status_code, 404)


class BaseSnippetViewSetTests(WagtailTestUtils, TestCase):
    model = None

    def setUp(self):
        self.user = self.login()

    def get_url(self, url_name, args=()):
        return reverse(self.model.snippet_viewset.get_url_name(url_name), args=args)


class TestCustomIcon(BaseSnippetViewSetTests):
    model = FullFeaturedSnippet

    def setUp(self):
        super().setUp()
        self.object = self.model.objects.create(text="test snippet with custom icon")
        self.revision_1 = self.object.save_revision()
        self.revision_1.publish()
        self.object.text = "test snippet with custom icon (updated)"
        self.revision_2 = self.object.save_revision()

    def test_get_views(self):

Review comment (suggestion):
The `url_prefix` doesn't include `/admin/`, so we need to add that to trigger the error

```suggestion
        response = self.client.get(f"/admin/{self.viewset.url_prefix}/edit/123/")
```

Code after:
    def test_unknown_converter(self):
        class BadViewSet(SnippetViewSet):
            model = AdvertTag
            pk_path_converter = "foo"

        with self.assertRaises(ImproperlyConfigured) as cm:
            register_snippet(BadViewSet)
        message = str(cm.exception)
        self.assertEqual(
            "BadViewSet.pk_path_converter is not a registered path converter",
            message,
        )


class BaseSnippetViewSetTests(WagtailTestUtils, TestCase):
    model = None

    def setUp(self):
        self.user = self.login()

    def get_url(self, url_name, args=()):
        return reverse(self.model.snippet_viewset.get_url_name(url_name), args=args)


class TestCustomIcon(BaseSnippetViewSetTests):
    model = FullFeaturedSnippet

    def setUp(self):
        super().setUp()
        self.object = self.model.objects.create(text="test snippet with custom icon")
        self.revision_1 = self.object.save_revision()
        self.revision_1.publish()
        self.object.text = "test snippet with custom icon (updated)"
        self.revision_2 = self.object.save_revision()

    def test_get_views(self):
        pk = quote(self.object.pk)
        views = [
            ("list", [], "headers/slim_header.html"),
            ("add", [], "headers/slim_header.html"),
            ("edit", [pk], "headers/slim_header.html"),
            ("delete", [pk], "header.html"),
            ("usage", [pk], "headers/slim_header.html"),
            ("unpublish", [pk], "header.html"),
            ("workflow_history", [pk], "headers/slim_header.html"),
            ("revisions_revert", [pk, self.revision_1.id], "headers/slim_header.html"),
            (
                "revisions_compare",
                [pk, self.revision_1.id, self.revision_2.id],
                "headers/slim_header.html",
            ),