예제 #1
0
    def test_detail_not_draft_staff(self, r2r, request_context):
        """
        Tests that a anyone viewing an entry can see it.
        """
        with patch('tekblog.views.get_object_or_404') as getter:
            getter.return_value = self.entry
            self.entry.draft = False
            self.request.user.is_staff = False

            detail(self.request, self.slug, template=self.details_template)
            self.assertTrue(r2r.called)
            self.assertTrue('entry' in get_context(r2r))
예제 #2
0
    def test_default_index(self, r2r, rc, get_by_model_call, paginator):
        """
        Tests that the normal flow of getting active items and rendering
        a response is called without a call to the get topics.
        """
        with patch('tekblog.views.Entry.objects.active') as active_call:
            active_call.return_value = self.results
            index(self.request)

            self.assertTrue(active_call.called)
            self.assertFalse(get_by_model_call.called)
            self.assertTrue(r2r.called)
            self.assertTrue('pager' in get_context(r2r))
예제 #3
0
    def test_default_index_topic(self, r2r, rc, get_by_model_call, paginator):
        """
        Tests that the normal flow of getting active items and rendering
        a response is called in addition to using the topic.
        """
        with patch('tekblog.views.Entry.objects.active') as active_call:
            active_call.return_value = self.results
            index(self.request, topic='Hello')

            get_by_model_call.assert_called_with(self.results, '"Hello"')

            self.assertTrue(active_call.called)
            self.assertTrue(get_by_model_call.called)
            self.assertTrue(r2r.called)
            self.assertTrue('pager' in get_context(r2r))
예제 #4
0
    def test_search_no_query_default(self, r2r, rc, all_call, sqs, empty_sqs,
            frm, pager):
        search(self.request)

        self.assertTrue(frm.called)
        self.assertFalse(frm.return_value.is_valid.called)

        # Ensure that render_to_response returns all the right context
        # variables
        self.assertTrue(r2r.called)
        context = get_context(r2r)
        self.assertEquals(context['form'], frm.return_value)
        self.assertEquals(context['page'],
                pager.return_value.page.return_value)
        self.assertEquals(context['paginator'], pager.return_value)
        self.assertEquals(context['query'], '')

        # The default results should be an empty query set
        self.assertEquals(context['results'], empty_sqs.return_value)
예제 #5
0
    def test_search_query_no_results(self, r2r, rc, all_call, sqs, empty_sqs,
            frm, pager):
        self.request.GET = {'q': 'tester'}
        search(self.request)

        self.assertTrue(frm.called)
        self.assertTrue(frm.return_value.is_valid.called)
        pager.assert_called_with(frm.return_value.search.return_value, 1000)

        # Ensure that render_to_response returns all the right context
        # variables
        self.assertTrue(r2r.called)
        context = get_context(r2r)
        self.assertEquals(context['form'], frm.return_value)
        self.assertEquals(context['page'],
                pager.return_value.page.return_value)
        self.assertEquals(context['paginator'], pager.return_value)
        self.assertEquals(context['query'], 'tester')

        # The results should be from the values returned from search
        self.assertEquals(context['results'],
                frm.return_value.search.return_value)