예제 #1
0
 def test_custom_layout(self):
     """if a custom template is used in a template then
     that will be used to render the page"""
     # write out the test template
     layout_path = '%s/unittest.html' % c_settings.CUSTOM_LAYOUTS
     layout = open(layout_path, 'w')
     layout.write('hello world')
     layout.close()
     # now make the page
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.status = Page.VISIBLE
     page1.layout = layout_path
     page1.save()
     # get the response and it is 'hello world'
     request = self.rf.get(reverse('ccpages:view', args=[1]))
     response = view(request, page1.slug)
     self.assertEqual('hello world', response.content)
     # remove the layout and it is not equal
     page1.layout = None
     page1.save()
     response = view(request, page1.slug)
     self.assertNotEqual('hello world', response.content)
     # delete the custom template
     os.unlink(layout_path)
예제 #2
0
 def test_view_200(self):
     """A visible page with no password returns a 200"""
     # make a page
     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 200
     request = self.rf.get(reverse('ccpages:view', args=[1]))
     response = view(request, page1.slug)
     self.assertEqual(200, response.status_code)
예제 #3
0
 def test_view_with_correct_hash(self):
     """if a user visits a page with the correct hash in their
     session the view returns a 200 response"""
     # 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 200
     request = self.rf.get(reverse('ccpages:view', args=[page1.slug]))
     hash = 'c0b0f36ffdfe68518916a0ea9d8a89cd2b4bc586'
     request.session['ccpage_1_hash'] = hash
     response = view(request, page1.slug)
     self.assertEqual(200, response.status_code)
예제 #4
0
 def test_view_password_redirects(self):
     """If there is a page with a password and the user isn't
     authed to view it then it redirects to the view view, but
     with a different url"""
     page1 = Page()
     page1.title = '1'
     page1.slug = '1'
     page1.content = '1'
     page1.order = Decimal('1')
     page1.status = Page.VISIBLE
     page1.password = '******'
     page1.save()
     # make request and we get a 302
     request = self.rf.get(reverse('ccpages:view', args=[1]))
     response = view(request, page1.slug)
     self.assertEqual(302, response.status_code)
     self.assertEqual(
             response['Location'],
             reverse('ccpages:password', args=[page1.slug]))