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

def testAddView(self):

    add_dict = {u'title': u'D\xf8m    ikke', u'content': u'<p>great    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.changeuser_login)
    self.assertEqual(self.client.session.test_cookie_worked(), False)
    response = self.client.get(u'/test_admin/admin/admin_views/article/add/')
    self.assertEqual(response.status_code, 403)
    post = self.client.post(u'/test_admin/admin/admin_views/article/add/', add_dict)
    self.assertEqual(post.status_code, 403)
    self.assertEqual(Article.objects.all().count(), 3)
    self.client.get(u'/test_admin/admin/logout/')
    self.client.get(u'/test_admin/admin/')
    self.client.post(u'/test_admin/admin/', self.adduser_login)
    addpage = self.client.get(u'/test_admin/admin/admin_views/article/add/')
    change_list_link = u'&rsaquo;    <a    href="/test_admin/admin/admin_views/article/">Articles</a>'
    self.assertNotContains(addpage, change_list_link, msg_prefix=u'User    restricted    to    add    permission    is    given    link    to    change    list    view    in    breadcrumbs.')
    post = self.client.post(u'/test_admin/admin/admin_views/article/add/', add_dict)
    self.assertRedirects(post, u'/test_admin/admin/')
    self.assertEqual(Article.objects.all().count(), 4)
    self.assertEqual(len(mail.outbox), 1)
    self.assertEqual(mail.outbox[0].subject, u'Greetings    from    a    created    object')
    self.client.get(u'/test_admin/admin/logout/')
    self.client.get(u'/test_admin/admin/')
    self.client.post(u'/test_admin/admin/', self.super_login)
    addpage = self.client.get(u'/test_admin/admin/admin_views/article/add/')
    self.assertContains(addpage, change_list_link, msg_prefix=u'Unrestricted    user    is    not    given    link    to    change    list    view    in    breadcrumbs.')
    post = self.client.post(u'/test_admin/admin/admin_views/article/add/', add_dict)
    self.assertRedirects(post, u'/test_admin/admin/admin_views/article/')
    self.assertEqual(Article.objects.all().count(), 5)
    self.client.get(u'/test_admin/admin/logout/')
    login = self.client.login(username=u'joepublic', password=u'secret')
    self.client.get(u'/test_admin/admin/')
    self.client.post(u'/test_admin/admin/', self.super_login)
    self.assertEqual(self.client.session.test_cookie_worked(), False)
