File: test_admin.py

package info (click to toggle)
python-django-parler 2.3-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,032 kB
  • sloc: python: 4,293; makefile: 164; sh: 6
file content (36 lines) | stat: -rw-r--r-- 1,449 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
from django.contrib.admin import AdminSite
from django.contrib.admin.utils import label_for_field

from parler.admin import TranslatableAdmin

from .testapp.models import AbstractModel, ConcreteModel, SimpleModel
from .utils import AppTestCase


class AdminTests(AppTestCase):
    """
    Test admin features
    """

    def test_list_label(self):
        # See that adding a field to the admin list_display also receives the translated title
        # This happens by TranslatedFieldDescriptor.short_description
        self.assertEqual(label_for_field("tr_title", SimpleModel), "Translated Title")

    def test_list_label_abc(self):
        # See that the TranslatedFieldDescriptor of the concrete model properly routes to the proper model
        self.assertEqual(label_for_field("tr_title", ConcreteModel), "Translated Title")

        # See that the TranslatedFieldDescriptor of the abstract model handles the fallback properly.
        self.assertEqual(label_for_field("tr_title", AbstractModel), "Tr title")

    def test_default_change_form_template(self):
        site = AdminSite()
        site.register(SimpleModel, TranslatableAdmin)
        admin = site._registry[SimpleModel]
        self.assertEqual(admin.default_change_form_template, "admin/change_form.html")

        # Avoid str + __proxy__ errors
        self.assertEqual(
            "default/" + admin.default_change_form_template, "default/admin/change_form.html"
        )