'Change view should restrict access and allow users to edit items.'

def testChangeView(self):

    change_dict = {u'title': u'Ikke    ford\xf8mt', u'content': u'<p>edited    article</p>', u'date_0': u'2008-03-18', u'date_1': u'10:54:39', u'section': 1}
    self.client.get(u'/test_admin/admin/')
    self.client.post(u'/test_admin/admin/', self.adduser_login)
    response = self.client.get(u'/test_admin/admin/admin_views/article/')
    self.assertEqual(response.status_code, 403)
    response = self.client.get(u'/test_admin/admin/admin_views/article/1/')
    self.assertEqual(response.status_code, 403)
    post = self.client.post(u'/test_admin/admin/admin_views/article/1/', change_dict)
    self.assertEqual(post.status_code, 403)
    self.client.get(u'/test_admin/admin/logout/')
    self.client.get(u'/test_admin/admin/')
    self.client.post(u'/test_admin/admin/', self.changeuser_login)
    response = self.client.get(u'/test_admin/admin/admin_views/article/')
    self.assertEqual(response.status_code, 200)
    response = self.client.get(u'/test_admin/admin/admin_views/article/1/')
    self.assertEqual(response.status_code, 200)
    post = self.client.post(u'/test_admin/admin/admin_views/article/1/', change_dict)
    self.assertRedirects(post, u'/test_admin/admin/admin_views/article/')
    self.assertEqual(Article.objects.get(pk=1).content, u'<p>edited    article</p>')
    change_dict[u'title'] = u''
    post = self.client.post(u'/test_admin/admin/admin_views/article/1/', change_dict)
    self.assertContains(post, u'Please    correct    the    error    below.', msg_prefix=u'Singular    error    message    not    found    in    response    to    post    with    one    error')
    change_dict[u'content'] = u''
    post = self.client.post(u'/test_admin/admin/admin_views/article/1/', change_dict)
    self.assertContains(post, u'Please    correct    the    errors    below.', msg_prefix=u'Plural    error    message    not    found    in    response    to    post    with    multiple    errors')
    self.client.get(u'/test_admin/admin/logout/')
    RowLevelChangePermissionModel.objects.create(id=1, name=u'odd    id')
    RowLevelChangePermissionModel.objects.create(id=2, name=u'even    id')
    for login_dict in [self.super_login, self.changeuser_login, self.adduser_login, self.deleteuser_login]:
        self.client.post(u'/test_admin/admin/', login_dict)
        response = self.client.get(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/')
        self.assertEqual(response.status_code, 403)
        response = self.client.post(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/', {u'name': u'changed'})
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, u'odd    id')
        self.assertEqual(response.status_code, 403)
        response = self.client.get(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/')
        self.assertEqual(response.status_code, 200)
        response = self.client.post(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/', {u'name': u'changed'})
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, u'changed')
        self.assertRedirects(response, u'/test_admin/admin/')
        self.client.get(u'/test_admin/admin/logout/')
    for login_dict in [self.joepublic_login, self.no_username_login]:
        self.client.post(u'/test_admin/admin/', login_dict)
        response = self.client.get(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'login-form')
        response = self.client.post(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/', {u'name': u'changed'})
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, u'odd    id')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'login-form')
        response = self.client.get(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'login-form')
        response = self.client.post(u'/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/', {u'name': u'changed    again'})
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, u'changed')
        self.assertEqual(response.status_code, 200)
        self.assertContains(response, u'login-form')
        self.client.get(u'/test_admin/admin/logout/')
