'Test add view restricts access and actually adds items.'

def test_add_view(self):

    add_dict = {'title': 'D\xc3\xb8m    ikke', 'content': '<p>great    article</p>', 'date_0': '2008-03-18', 'date_1': '10:54:39', 'section': self.s1.pk}
    self.client.force_login(self.changeuser)
    self.assertIs(self.client.session.test_cookie_worked(), False)
    response = self.client.get(reverse('admin:admin_views_article_add'))
    self.assertEqual(response.status_code, 403)
    post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
    self.assertEqual(post.status_code, 403)
    self.assertEqual(Article.objects.count(), 3)
    self.client.get(reverse('admin:logout'))
    self.client.force_login(self.adduser)
    addpage = self.client.get(reverse('admin:admin_views_article_add'))
    change_list_link = ('&rsaquo;    <a    href="%s">Articles</a>' % reverse('admin:admin_views_article_changelist'))
    self.assertNotContains(addpage, change_list_link, msg_prefix='User    restricted    to    add    permission    is    given    link    to    change    list    view    in    breadcrumbs.')
    post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
    self.assertRedirects(post, self.index_url)
    self.assertEqual(Article.objects.count(), 4)
    self.assertEqual(len(mail.outbox), 1)
    self.assertEqual(mail.outbox[0].subject, 'Greetings    from    a    created    object')
    self.client.get(reverse('admin:logout'))
    addition_log = LogEntry.objects.all()[0]
    new_article = Article.objects.last()
    article_ct = ContentType.objects.get_for_model(Article)
    self.assertEqual(addition_log.user_id, self.adduser.pk)
    self.assertEqual(addition_log.content_type_id, article_ct.pk)
    self.assertEqual(addition_log.object_id, str(new_article.pk))
    self.assertEqual(addition_log.object_repr, 'D\xc3\xb8m    ikke')
    self.assertEqual(addition_log.action_flag, ADDITION)
    self.assertEqual(addition_log.get_change_message(), 'Added.')
    self.client.force_login(self.superuser)
    addpage = self.client.get(reverse('admin:admin_views_article_add'))
    self.assertContains(addpage, change_list_link, msg_prefix='Unrestricted    user    is    not    given    link    to    change    list    view    in    breadcrumbs.')
    post = self.client.post(reverse('admin:admin_views_article_add'), add_dict)
    self.assertRedirects(post, reverse('admin:admin_views_article_changelist'))
    self.assertEqual(Article.objects.count(), 5)
    self.client.get(reverse('admin:logout'))
    self.client.force_login(self.joepublicuser)
    self.client.force_login(self.superuser)
    self.assertIs(self.client.session.test_cookie_worked(), False)
