Example #1
0
    def test_pagination(self):
        """Testing SearchView pagination"""
        user = self.create_user()
        diffset_history = DiffSetHistory.objects.create()

        ReviewRequest.objects.bulk_create(
            ReviewRequest(diffset_history=diffset_history,
                          summary='Test %s' % i,
                          submitter=user,
                          public=True) for i in range(20))

        siteconfig_settings = {
            'search_results_per_page': 1,
        }

        with search_enabled(backend_id='whoosh'):
            with self.siteconfig_settings(siteconfig_settings,
                                          reload_settings=False):
                reindex_search()
                rsp = self.client.get('%s?q=Test&page=10' % reverse('search'))

        self.assertEqual(rsp.status_code, 200)

        self.assertIn(
            b'<a href="?q=Test&amp;page=1" rel="nofollow">'
            b'&laquo; First Page</a>', rsp.content)
        self.assertIn(
            b'<a href="?q=Test&amp;page=9" rel="nofollow">'
            b'&lt; Previous</a>', rsp.content)
        self.assertIn(
            b'<a href="?q=Test&amp;page=11" rel="nofollow">'
            b'Next &gt;</a>', rsp.content)
        self.assertIn(
            b'<a href="?q=Test&amp;page=20" rel="nofollow">'
            b'Last Page &raquo;</a>', rsp.content)
Example #2
0
    def test_get_user_public_profile_indexed(self):
        """Testing the GET <URL> API with the search index enabled and
        on-the-fly indexing enabled for a user with a public profile
        """
        with search_enabled(on_the_fly_indexing=True):
            reindex_search()
            rsp = self.api_get(get_search_url(),
                               query={'q': 'doc'},
                               expected_mimetype=search_mimetype)

        search_results = rsp['search']
        self.assertEqual(len(search_results['groups']), 0)
        self.assertEqual(len(search_results['review_requests']), 0)
        self.assertEqual(len(search_results['users']), 1)

        item_rsp = search_results['users'][0]
        self.assertIn('fullname', item_rsp)
Example #3
0
    def test_get_user_public_profile_indexed(self):
        """Testing the GET <URL> API with the search index enabled and
        on-the-fly indexing enabled for a user with a public profile
        """
        with search_enabled(on_the_fly_indexing=True):
            reindex_search()
            rsp = self.api_get(get_search_url(),
                               query={'q': 'doc'},
                               expected_mimetype=search_mimetype)

        search_results = rsp['search']
        self.assertEqual(len(search_results['groups']), 0)
        self.assertEqual(len(search_results['review_requests']), 0)
        self.assertEqual(len(search_results['users']), 1)

        item_rsp = search_results['users'][0]
        self.assertIn('fullname', item_rsp)
Example #4
0
    def test_get_from_search_index_on_the_fly(self):
        """Testing the GET <URL> API with the search index enabled and
        on-the-fly indexing enabled
        """
        self.create_review_request(submitter=self.user, public=True)

        self.spy_on(resources.review_request.serialize_object)
        self.spy_on(resources.user.serialize_object)

        with search_enabled(on_the_fly_indexing=True):
            reindex_search()
            rsp = self.api_get(get_search_url(),
                               query={'q': self.user.username},
                               expected_mimetype=search_mimetype)

        self.assertEqual(len(rsp['search']['groups']), 0)
        self.assertEqual(len(rsp['search']['review_requests']), 1)
        self.assertEqual(len(rsp['search']['users']), 1)

        self.assertFalse(resources.review_request.serialize_object.spy.called)
        self.assertFalse(resources.user.serialize_object.spy.called)
Example #5
0
    def test_get_from_search_index_on_the_fly(self):
        """Testing the GET <URL> API with the search index enabled and
        on-the-fly indexing enabled
        """
        self.create_review_request(submitter=self.user, public=True)

        self.spy_on(resources.review_request.serialize_object)
        self.spy_on(resources.user.serialize_object)

        with search_enabled(on_the_fly_indexing=True):
            reindex_search()
            rsp = self.api_get(get_search_url(),
                               query={'q': self.user.username},
                               expected_mimetype=search_mimetype)

        self.assertEqual(len(rsp['search']['groups']), 0)
        self.assertEqual(len(rsp['search']['review_requests']), 1)
        self.assertEqual(len(rsp['search']['users']), 1)

        self.assertFalse(resources.review_request.serialize_object.spy.called)
        self.assertFalse(resources.user.serialize_object.spy.called)
Example #6
0
    def test_get_private_user_indexed(self):
        """Testing the GET <URL> API with the search index enabled and
        on-the-fly indexing enabled for a user with a private profile
        """
        profile = Profile.objects.get(user__username='******')
        profile.is_private = True
        profile.save()

        with search_enabled(on_the_fly_indexing=True):
            reindex_search()
            rsp = self.api_get(get_search_url(),
                               query={'q': 'doc'},
                               expected_mimetype=search_mimetype)

        search_results = rsp['search']
        self.assertEqual(len(search_results['groups']), 0)
        self.assertEqual(len(search_results['review_requests']), 0)
        self.assertEqual(len(search_results['users']), 1)

        profile = Profile.objects.get(user__username='******')
        item_rsp = search_results['users'][0]
        self.assertNotIn('fullname', item_rsp)
Example #7
0
    def test_get_private_user_indexed(self):
        """Testing the GET <URL> API with the search index enabled and
        on-the-fly indexing enabled for a user with a private profile
        """
        profile = Profile.objects.get(user__username='******')
        profile.is_private = True
        profile.save(update_fields=('is_private',))

        with search_enabled(on_the_fly_indexing=True):
            reindex_search()
            rsp = self.api_get(get_search_url(),
                               query={'q': 'doc'},
                               expected_mimetype=search_mimetype)

        search_results = rsp['search']
        self.assertEqual(len(search_results['groups']), 0)
        self.assertEqual(len(search_results['review_requests']), 0)
        self.assertEqual(len(search_results['users']), 1)

        profile = Profile.objects.get(user__username='******')
        item_rsp = search_results['users'][0]
        self.assertNotIn('fullname', item_rsp)