Ejemplo n.º 1
0
 def test_when_no_homepage_throws_404(self):
     home = reverse('pages:index')
     request = RequestFactory().get(home)
     view = Homepage.as_view()
     with self.assertRaises(Http404):
         with self.assertNumQueries(1):
             view(request)
Ejemplo n.º 2
0
 def test_when_homepage_exists(self):
     home = reverse('pages:index')
     request = RequestFactory().get(home)
     view = Homepage.as_view()
     mommy.make(Page, is_homepage=True, template='test.html')
     with self.assertNumQueries(1):
         response = view(request)
     self.assertIn('Allow', response)
     self.assertIsInstance(response, TemplateResponse)
     with self.assertRaises(TemplateDoesNotExist):
         response.render()
Ejemplo n.º 3
0
 def test_when_no_homepage_shows_debug_page_in_debug(self):
     home = reverse('pages:index')
     request = RequestFactory().get(home)
     view = Homepage.as_view()
     num_queries = 2
     # no-one knows why ...
     if django.VERSION[:2] <= (1, 5):
         num_queries = 1
     with self.assertNumQueries(num_queries):
         response = view(request)
     self.assertEqual(response.status_code, 404)
     self.assertIsInstance(response, TemplateResponse)