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

« back to all changes in this revision

Viewing changes to tests/regressiontests/admin_views/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:
1477
1477
        response = self.client.post('/test_admin/admin/admin_views/externalsubscriber/', action_data)
1478
1478
        self.failUnlessEqual(response.status_code, 302)
1479
1479
 
 
1480
    def test_default_redirect(self):
 
1481
        """
 
1482
        Test that actions which don't return an HttpResponse are redirected to
 
1483
        the same page, retaining the querystring (which may contain changelist
 
1484
        information).
 
1485
        """
 
1486
        action_data = {
 
1487
            ACTION_CHECKBOX_NAME: [1],
 
1488
            'action' : 'external_mail',
 
1489
            'index': 0,
 
1490
        }
 
1491
        url = '/test_admin/admin/admin_views/externalsubscriber/?ot=asc&o=1'
 
1492
        response = self.client.post(url, action_data)
 
1493
        self.assertRedirects(response, url)
 
1494
 
1480
1495
    def test_model_without_action(self):
1481
1496
        "Tests a ModelAdmin without any action"
1482
1497
        response = self.client.get('/test_admin/admin/admin_views/oldsubscriber/')
2113
2128
        response = self.client.get('/test_admin/admin/admin_views/pizza/add/')
2114
2129
        self.assertEqual(response.status_code, 200)
2115
2130
 
2116
 
class IncompleteFormTest(TestCase):
 
2131
class UserAdminTest(TestCase):
2117
2132
    """
2118
 
    Tests validation of a ModelForm that doesn't explicitly have all data
2119
 
    corresponding to model fields. Model validation shouldn't fail
2120
 
    such a forms.
 
2133
    Tests user CRUD functionality.
2121
2134
    """
2122
2135
    fixtures = ['admin-views-users.xml']
2123
2136
 
2128
2141
        self.client.logout()
2129
2142
 
2130
2143
    def test_user_creation(self):
 
2144
        user_count = User.objects.count()
2131
2145
        response = self.client.post('/test_admin/admin/auth/user/add/', {
2132
2146
            'username': 'newuser',
2133
2147
            'password1': 'newpassword',
2136
2150
        })
2137
2151
        new_user = User.objects.order_by('-id')[0]
2138
2152
        self.assertRedirects(response, '/test_admin/admin/auth/user/%s/' % new_user.pk)
 
2153
        self.assertEquals(User.objects.count(), user_count + 1)
2139
2154
        self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
2140
2155
 
2141
2156
    def test_password_mismatch(self):
2149
2164
        self.assert_('password' not in adminform.form.errors)
2150
2165
        self.assertEquals(adminform.form.errors['password2'],
2151
2166
                          [u"The two password fields didn't match."])
 
2167
 
 
2168
    def test_user_fk_popup(self):
 
2169
        response = self.client.get('/test_admin/admin/admin_views/album/add/')
 
2170
        self.failUnlessEqual(response.status_code, 200)
 
2171
        self.assertContains(response, '/test_admin/admin/auth/user/add')
 
2172
        self.assertContains(response, 'class="add-another" id="add_id_owner" onclick="return showAddAnotherPopup(this);"')
 
2173
        response = self.client.get('/test_admin/admin/auth/user/add/?_popup=1')
 
2174
        self.assertNotContains(response, 'name="_continue"')
 
2175
 
 
2176
    def test_user_add_another(self):
 
2177
        user_count = User.objects.count()
 
2178
        response = self.client.post('/test_admin/admin/auth/user/add/', {
 
2179
            'username': 'newuser',
 
2180
            'password1': 'newpassword',
 
2181
            'password2': 'newpassword',
 
2182
            '_addanother': '1',
 
2183
        })
 
2184
        new_user = User.objects.order_by('-id')[0]
 
2185
        self.assertRedirects(response, '/test_admin/admin/auth/user/add/')
 
2186
        self.assertEquals(User.objects.count(), user_count + 1)
 
2187
        self.assertNotEquals(new_user.password, UNUSABLE_PASSWORD)
 
2188
 
 
2189
try:
 
2190
    # If docutils isn't installed, skip the AdminDocs tests.
 
2191
    import docutils
 
2192
 
 
2193
    class AdminDocsTest(TestCase):
 
2194
        fixtures = ['admin-views-users.xml']
 
2195
 
 
2196
        def setUp(self):
 
2197
            self.client.login(username='super', password='secret')
 
2198
 
 
2199
        def tearDown(self):
 
2200
            self.client.logout()
 
2201
 
 
2202
        def test_tags(self):
 
2203
            response = self.client.get('/test_admin/admin/doc/tags/')
 
2204
 
 
2205
            # The builtin tag group exists
 
2206
            self.assertContains(response, "<h2>Built-in tags</h2>", count=2)
 
2207
 
 
2208
            # A builtin tag exists in both the index and detail
 
2209
            self.assertContains(response, '<h3 id="built_in-autoescape">autoescape</h3>')
 
2210
            self.assertContains(response, '<li><a href="#built_in-autoescape">autoescape</a></li>')
 
2211
 
 
2212
            # An app tag exists in both the index and detail
 
2213
            self.assertContains(response, '<h3 id="comments-get_comment_count">get_comment_count</h3>')
 
2214
            self.assertContains(response, '<li><a href="#comments-get_comment_count">get_comment_count</a></li>')
 
2215
 
 
2216
            # The admin list tag group exists
 
2217
            self.assertContains(response, "<h2>admin_list</h2>", count=2)
 
2218
 
 
2219
            # An admin list tag exists in both the index and detail
 
2220
            self.assertContains(response, '<h3 id="admin_list-admin_actions">admin_actions</h3>')
 
2221
            self.assertContains(response, '<li><a href="#admin_list-admin_actions">admin_actions</a></li>')
 
2222
 
 
2223
        def test_filters(self):
 
2224
            response = self.client.get('/test_admin/admin/doc/filters/')
 
2225
 
 
2226
            # The builtin filter group exists
 
2227
            self.assertContains(response, "<h2>Built-in filters</h2>", count=2)
 
2228
 
 
2229
            # A builtin filter exists in both the index and detail
 
2230
            self.assertContains(response, '<h3 id="built_in-add">add</h3>')
 
2231
            self.assertContains(response, '<li><a href="#built_in-add">add</a></li>')
 
2232
 
 
2233
except ImportError:
 
2234
    pass