Ticket #18051: ticket18051-2.diff

File ticket18051-2.diff, 2.1 KB (added by mateusgondim, 12 years ago)

Added tests.

  • django/contrib/admin/util.py

    diff --git a/django/contrib/admin/util.py b/django/contrib/admin/util.py
    index 9611b00..224fd86 100644
    a b def flatten_fieldsets(fieldsets):  
    8787    for name, opts in fieldsets:
    8888        for field in opts['fields']:
    8989            # type checking feels dirty, but it seems like the best way here
    90             if type(field) == tuple:
     90            if isinstance(field, (list, tuple)):
    9191                field_names.extend(field)
    9292            else:
    9393                field_names.append(field)
  • tests/regressiontests/admin_util/tests.py

    diff --git a/tests/regressiontests/admin_util/tests.py b/tests/regressiontests/admin_util/tests.py
    index 055f494..08336cf 100644
    a b from django.conf import settings  
    66from django.contrib import admin
    77from django.contrib.admin import helpers
    88from django.contrib.admin.util import (display_for_field, label_for_field,
    9     lookup_field, NestedObjects)
     9    lookup_field, NestedObjects, flatten_fieldsets)
    1010from django.contrib.admin.views.main import EMPTY_CHANGELIST_VALUE
    1111from django.contrib.sites.models import Site
    1212from django.db import models, DEFAULT_DB_ALIAS
    class UtilTests(unittest.TestCase):  
    284284                         '<label for="id_text" class="required inline">&amp;text:</label>')
    285285        self.assertEqual(helpers.AdminField(form, 'cb', is_first=False).label_tag(),
    286286                         '<label for="id_cb" class="vCheckboxLabel required inline">&amp;cb</label>')
     287
     288    def test_flatten_fieldsets(self):
     289        """
     290        Regression test for #18051
     291        """
     292        fieldsets = (
     293            (None, {
     294                'fields': ('url', 'title', ('content', 'sites'))
     295            }),
     296        )
     297        self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])
     298
     299        fieldsets = (
     300            (None, {
     301                'fields': ('url', 'title', ['content', 'sites'])
     302            }),
     303        )
     304        self.assertEqual(flatten_fieldsets(fieldsets), ['url', 'title', 'content', 'sites'])
Back to Top