Ticket #13599: improved_tests_base.diff

File improved_tests_base.diff, 3.6 KB (added by jbronn, 14 years ago)
  • tests/regressiontests/admin_changelist/tests.py

     
    1 import unittest
    21from django.contrib import admin
    32from django.contrib.admin.views.main import ChangeList
    43from django.template import Context, Template
     4from django.test import TransactionTestCase
    55from regressiontests.admin_changelist.models import Child, Parent
    66
    7 class ChangeListTests(unittest.TestCase):
     7class ChangeListTests(TransactionTestCase):
    88    def test_select_related_preserved(self):
    99        """
    1010        Regression test for #10348: ChangeList.get_query_set() shouldn't
     
    1717        self.assertEqual(cl.query_set.query.select_related, {'parent': {'name': {}}})
    1818
    1919    def test_result_list_html(self):
    20         """
    21         Regression test for #11791: Inclusion tag result_list generates a
    22         table and this checks that the items are nested within the table
    23         element tags.
    24         """
    2520        new_parent = Parent.objects.create(name='parent')
    2621        new_child = Child.objects.create(name='name', parent=new_parent)
    2722        request = MockRequest()
     
    2924        cl = ChangeList(request, Child, m.list_display, m.list_display_links,
    3025                m.list_filter, m.date_hierarchy, m.search_fields,
    3126                m.list_select_related, m.list_per_page, m.list_editable, m)
    32         FormSet = m.get_changelist_formset(request)
    33         cl.formset = FormSet(queryset=cl.result_list)
     27        cl.formset = None
    3428        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
    3529        context = Context({'cl': cl})
    3630        table_output = template.render(context)
    37         hidden_input_elem = '<input type="hidden" name="form-0-id" value="1" id="id_form-0-id" />'
    38         self.failIf(table_output.find(hidden_input_elem) == -1,
    39             'Failed to find expected hidden input element in: %s' % table_output)
    40         self.failIf(table_output.find('<td>%s</td>' % hidden_input_elem) == -1,
    41             'Hidden input element is not enclosed in <td> element.')
     31        row_html = '<tbody><tr class="row1"><td><input type="checkbox" class="action-select" value="1" name="_selected_action" /></td><th><a href="1/">name</a></th><td>Parent object</td></tr></tbody>'
     32        self.failIf(table_output.find(row_html) == -1,
     33            'Failed to find expected row element: %s' % table_output)
    4234
     35    def test_result_list_editable_html(self):
     36        """
     37        Regression test for #11791: Inclusion tag result_list generates a
     38        table and this checks that the items are nested within the table
     39        element tags.
     40        """
     41        new_parent = Parent.objects.create(name='parent')
     42        new_child = Child.objects.create(name='name', parent=new_parent)
     43        request = MockRequest()
     44        m = ChildAdmin(Child, admin.site)
     45
    4346        # Test with list_editable fields
    4447        m.list_display = ['id', 'name', 'parent']
    4548        m.list_display_links = ['id']
     
    5255        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
    5356        context = Context({'cl': cl})
    5457        table_output = template.render(context)
     58        hidden_input_elem = '<input type="hidden" name="form-0-id" value="1" id="id_form-0-id" />'
    5559        self.failIf(table_output.find(hidden_input_elem) == -1,
    5660            'Failed to find expected hidden input element in: %s' % table_output)
    5761        self.failIf(table_output.find('<td>%s</td>' % hidden_input_elem) == -1,
Back to Top