Repository: wagtail/wagtail
File: wagtail/admin/tests/tests.py (Python)

Code before:
import json
import unittest

from django.conf import settings
from django.contrib.auth.models import Group, Permission
from django.core import mail
from django.core.management import call_command
from django.test import TestCase, override_settings
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
from taggit.models import Tag

from wagtail.admin.auth import user_has_any_page_permission
from wagtail.admin.mail import send_mail
from wagtail.admin.menu import MenuItem
from wagtail.admin.views.tags import WAGTAIL_TAGS_AUTOCOMPLETE_LIMIT
from wagtail.models import Page
from wagtail.test.testapp.models import RestaurantTag
from wagtail.test.utils import WagtailTestUtils
from wagtail.utils.deprecation import (
    RemovedInWagtail70Warning,
)


class TestHome(WagtailTestUtils, TestCase):
    def setUp(self):
        # Login
        self.login()

    def test_simple(self):
        response = self.client.get(reverse("wagtailadmin_home"))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Test Site")

    def test_admin_menu(self):
        response = self.client.get(reverse("wagtailadmin_home"))
        self.assertEqual(response.status_code, 200)
        # check that custom menu items (including classname / icon_name) are pulled in
        self.assertContains(
            response,
            '{"name": "kittens", "label": "Kittens!", "icon_name": "kitten", "classname": "kitten--test", "attrs": {"data-is-custom": "true"}, "url": "http://www.tomroyal.com/teaandkittens/"}',

Review comment (bug):
@aayushman-singh  I see what you were intending here but this change will not actually test that there are ten items but just that the import is used to reflect the item limit.

Which means if there's a typo in this value or something else wrong, it will not throw an error in the test.

Instead, we should leave this test as is and leave the 'internal implementation' of that module outside of the tests.

If there's a future where this gets converted into a setting, then we would create new tests for this.

Code after:
import json
import unittest

from django.conf import settings
from django.contrib.auth.models import Group, Permission
from django.core import mail
from django.core.management import call_command
from django.test import TestCase, override_settings
from django.urls import reverse, reverse_lazy
from django.utils.translation import gettext_lazy as _
from taggit.models import Tag

from wagtail.admin.auth import user_has_any_page_permission
from wagtail.admin.mail import send_mail
from wagtail.admin.menu import MenuItem
from wagtail.models import Page
from wagtail.test.testapp.models import RestaurantTag
from wagtail.test.utils import WagtailTestUtils
from wagtail.utils.deprecation import (
    RemovedInWagtail70Warning,
)


class TestHome(WagtailTestUtils, TestCase):
    def setUp(self):
        # Login
        self.login()

    def test_simple(self):
        response = self.client.get(reverse("wagtailadmin_home"))
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, "Test Site")

    def test_admin_menu(self):
        response = self.client.get(reverse("wagtailadmin_home"))
        self.assertEqual(response.status_code, 200)
        # check that custom menu items (including classname / icon_name) are pulled in
        self.assertContains(
            response,
            '{"name": "kittens", "label": "Kittens!", "icon_name": "kitten", "classname": "kitten--test", "attrs": {"data-is-custom": "true"}, "url": "http://www.tomroyal.com/teaandkittens/"}',
        )