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

def test_change_view(self):

    change_dict = {'title': 'Ikke    ford\xc3\xb8mt', 'content': '<p>edited    article</p>', 'date_0': '2008-03-18', 'date_1': '10:54:39', 'section': self.s1.pk}
    article_change_url = reverse('admin:admin_views_article_change', args=(self.a1.pk,))
    article_changelist_url = reverse('admin:admin_views_article_changelist')
    self.client.force_login(self.adduser)
    response = self.client.get(article_changelist_url)
    self.assertEqual(response.status_code, 403)
    response = self.client.get(article_change_url)
    self.assertEqual(response.status_code, 403)
    post = self.client.post(article_change_url, change_dict)
    self.assertEqual(post.status_code, 403)
    self.client.get(reverse('admin:logout'))
    self.client.force_login(self.changeuser)
    response = self.client.get(article_changelist_url)
    self.assertEqual(response.status_code, 200)
    response = self.client.get(article_change_url)
    self.assertEqual(response.status_code, 200)
    post = self.client.post(article_change_url, change_dict)
    self.assertRedirects(post, article_changelist_url)
    self.assertEqual(Article.objects.get(pk=self.a1.pk).content, '<p>edited    article</p>')
    change_dict['title'] = ''
    post = self.client.post(article_change_url, change_dict)
    self.assertContains(post, 'Please    correct    the    error    below.', msg_prefix='Singular    error    message    not    found    in    response    to    post    with    one    error')
    change_dict['content'] = ''
    post = self.client.post(article_change_url, change_dict)
    self.assertContains(post, 'Please    correct    the    errors    below.', msg_prefix='Plural    error    message    not    found    in    response    to    post    with    multiple    errors')
    self.client.get(reverse('admin:logout'))
    r1 = RowLevelChangePermissionModel.objects.create(id=1, name='odd    id')
    r2 = RowLevelChangePermissionModel.objects.create(id=2, name='even    id')
    change_url_1 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r1.pk,))
    change_url_2 = reverse('admin:admin_views_rowlevelchangepermissionmodel_change', args=(r2.pk,))
    for login_user in [self.superuser, self.adduser, self.changeuser, self.deleteuser]:
        self.client.force_login(login_user)
        response = self.client.get(change_url_1)
        self.assertEqual(response.status_code, 403)
        response = self.client.post(change_url_1, {'name': 'changed'})
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd    id')
        self.assertEqual(response.status_code, 403)
        response = self.client.get(change_url_2)
        self.assertEqual(response.status_code, 200)
        response = self.client.post(change_url_2, {'name': 'changed'})
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
        self.assertRedirects(response, self.index_url)
        self.client.get(reverse('admin:logout'))
    for login_user in [self.joepublicuser, self.nostaffuser]:
        self.client.force_login(login_user)
        response = self.client.get(change_url_1, follow=True)
        self.assertContains(response, 'login-form')
        response = self.client.post(change_url_1, {'name': 'changed'}, follow=True)
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd    id')
        self.assertContains(response, 'login-form')
        response = self.client.get(change_url_2, follow=True)
        self.assertContains(response, 'login-form')
        response = self.client.post(change_url_2, {'name': 'changed    again'}, follow=True)
        self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
        self.assertContains(response, 'login-form')
        self.client.get(reverse('admin:logout'))
