Beispiel #1
0
    def test_search_any_word_in_indexed_fields(self):
        """Test search any word in indexed fields.

        :return:
        """
        # Create some data to test
        book = factories.BookWithUniqueTitleFactory(
            title='This is a short indexed description')
        factories.BookWithUniqueTitleFactory.create_batch(100)
        self._reindex()
        sleep(3)  # Wait until indexed
        url = reverse('bookdocument-list', kwargs={})

        self._test_search_any_word_in_indexed_fields(
            search_term='short indexed description',
            url=url,
            expected_num_results=1,
            title_match=book.title,
            create_factory=False)
        self._test_search_any_word_in_indexed_fields(
            search_term='a description',
            url=url,
            expected_num_results=1,
            title_match=book.title,
            create_factory=False)

        self._test_search_any_word_in_indexed_fields(
            search_term='short description',
            url=url,
            expected_num_results=1,
            title_match=book.title,
            create_factory=False)
Beispiel #2
0
    def _test_search_any_word_in_indexed_fields(self,
                                                search_term,
                                                url,
                                                expected_num_results,
                                                title_match=None,
                                                create_factory=False):
        if create_factory:
            factories.BookWithUniqueTitleFactory(
                title='This is a short indexed description'
            )
            factories.BookWithUniqueTitleFactory.create_batch(100)
            self._reindex()

        self.authenticate()
        filtered_url = url + '?search={}'.format(search_term)
        filtered_response = self.client.get(filtered_url)
        self.assertEqual(filtered_response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            len(filtered_response.data['results']),
            expected_num_results
        )
        if title_match:
            self.assertEqual(
                filtered_response.data['results'][0]['title'],
                title_match
            )