def test_password_200(self):
     """The password page responds with a 200 ok"""
     # make a page
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.password = '******'
     page1.status = Page.VISIBLE
     page1.save()
     # make post request and we get a 200
     request = self.rf.get(
             reverse('ccpages:password', args=[page1.slug]))
     response = password(request, page1.slug)
     self.assertEqual(200, response.status_code)
 def test_password_redirects_back_if_page_has_no_password(self):
     """if a page has no password and the user attempts to access
     the password page, they are redirected back"""
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.status = Page.VISIBLE
     page1.save()
     # make request and we get a 302
     request = self.rf.get(reverse('ccpages:password', args=[1]))
     response = password(request, page1.slug)
     self.assertEqual(302, response.status_code)
     self.assertEqual(
             response['Location'],
             reverse('ccpages:view', args=[page1.slug]))
 def test_password_post_incorrect_password(self):
     """When the incorrect password for a page is sent via post
     the users session is updated to include a hash that allows
     access"""
     # make a page
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.password = '******'
     page1.status = Page.VISIBLE
     page1.save()
     # make post request and we get a 200
     request = self.rf.post(
             reverse('ccpages:password', args=[page1.slug]),
             {'password': '******'})
     response = password(request, page1.slug)
     self.assertEqual(200, response.status_code)
 def test_password_post_correct_password(self):
     """When the correct password for a page is sent via post
     the users session is updated to include a hash that allows
     access"""
     # make a page
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.password = '******'
     page1.status = Page.VISIBLE
     page1.save()
     # make request and we get a 302
     request = self.rf.post(
             reverse('ccpages:password', args=[page1.slug]),
             {'password': '******'})
     response = password(request, page1.slug)
     self.assertEqual(302, response.status_code)
     # and now the session has the key and a hash in it
     self.assertEqual(
             request.session['ccpage_1_hash'],
             'c0b0f36ffdfe68518916a0ea9d8a89cd2b4bc586')