~ubuntu-branches/ubuntu/oneiric/python-django/oneiric-201108291626

« back to all changes in this revision

Viewing changes to tests/regressiontests/admin_changelist/tests.py

  • Committer: Bazaar Package Importer
  • Author(s): Jamie Strandboge
  • Date: 2010-10-12 11:34:35 UTC
  • mfrom: (1.1.12 upstream) (29.1.1 maverick-security)
  • Revision ID: james.westby@ubuntu.com-20101012113435-yy57c8tx6g9anf3e
Tags: 1.2.3-1ubuntu0.1
* SECURITY UPDATE: XSS in CSRF protections. New upstream release
  - CVE-2010-3082
* debian/patches/01_disable_url_verify_regression_tests.diff:
  - updated to disable another test that fails without internet connection
  - patch based on work by Kai Kasurinen and Krzysztof Klimonda
* debian/control: don't Build-Depends on locales-all, which doesn't exist
  in maverick

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
import unittest 
2
1
from django.contrib import admin
3
2
from django.contrib.admin.views.main import ChangeList
4
3
from django.template import Context, Template
 
4
from django.test import TransactionTestCase
5
5
from regressiontests.admin_changelist.models import Child, Parent
6
6
 
7
 
class ChangeListTests(unittest.TestCase):
 
7
class ChangeListTests(TransactionTestCase):
8
8
    def test_select_related_preserved(self):
9
9
        """
10
10
        Regression test for #10348: ChangeList.get_query_set() shouldn't
18
18
 
19
19
    def test_result_list_html(self):
20
20
        """
21
 
        Regression test for #11791: Inclusion tag result_list generates a 
 
21
        Verifies that inclusion tag result_list generates a table when with
 
22
        default ModelAdmin settings.
 
23
        """
 
24
        new_parent = Parent.objects.create(name='parent')
 
25
        new_child = Child.objects.create(name='name', parent=new_parent)
 
26
        request = MockRequest()
 
27
        m = ChildAdmin(Child, admin.site)
 
28
        cl = ChangeList(request, Child, m.list_display, m.list_display_links, 
 
29
                m.list_filter, m.date_hierarchy, m.search_fields, 
 
30
                m.list_select_related, m.list_per_page, m.list_editable, m)
 
31
        cl.formset = None
 
32
        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
 
33
        context = Context({'cl': cl})
 
34
        table_output = template.render(context)
 
35
        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>'
 
36
        self.failIf(table_output.find(row_html) == -1,
 
37
            'Failed to find expected row element: %s' % table_output)
 
38
 
 
39
    def test_result_list_editable_html(self):
 
40
        """
 
41
        Regression tests for #11791: Inclusion tag result_list generates a 
22
42
        table and this checks that the items are nested within the table
23
43
        element tags.
 
44
        Also a regression test for #13599, verifies that hidden fields
 
45
        when list_editable is enabled are rendered in a div outside the 
 
46
        table.
24
47
        """
25
48
        new_parent = Parent.objects.create(name='parent')
26
49
        new_child = Child.objects.create(name='name', parent=new_parent)
27
50
        request = MockRequest()
28
51
        m = ChildAdmin(Child, admin.site)
29
 
        cl = ChangeList(request, Child, m.list_display, m.list_display_links, 
30
 
                m.list_filter, m.date_hierarchy, m.search_fields, 
31
 
                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)
34
 
        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
35
 
        context = Context({'cl': cl})
36
 
        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.')
42
52
 
43
53
        # Test with list_editable fields
44
54
        m.list_display = ['id', 'name', 'parent']
52
62
        template = Template('{% load admin_list %}{% spaceless %}{% result_list cl %}{% endspaceless %}')
53
63
        context = Context({'cl': cl})
54
64
        table_output = template.render(context)
55
 
        self.failIf(table_output.find(hidden_input_elem) == -1,
56
 
            'Failed to find expected hidden input element in: %s' % table_output)
57
 
        self.failIf(table_output.find('<td>%s</td>' % hidden_input_elem) == -1,
58
 
            'Hidden input element is not enclosed in <td> element.')
 
65
        # make sure that hidden fields are in the correct place
 
66
        hiddenfields_div = '<div class="hiddenfields"><input type="hidden" name="form-0-id" value="1" id="id_form-0-id" /></div>'
 
67
        self.failIf(table_output.find(hiddenfields_div) == -1,
 
68
            'Failed to find hidden fields in: %s' % table_output)
 
69
        # make sure that list editable fields are rendered in divs correctly
 
70
        editable_name_field = '<input name="form-0-name" value="name" class="vTextField" maxlength="30" type="text" id="id_form-0-name" />'
 
71
        self.failIf('<td>%s</td>' % editable_name_field == -1,
 
72
            'Failed to find "name" list_editable field in: %s' % table_output)
59
73
 
60
74
class ChildAdmin(admin.ModelAdmin):
61
75
    list_display = ['name', 'parent']