Exemplo n.º 1
0
    def test_filter_missing(self):

        search_terms = {'contributors': None}
        filter_set = ElasticutilsFilterSet(search_fields=self.search_fields,
                                           search_actions=None,
                                           search_terms=search_terms,
                                           mapping_type=self.mapping_type,
                                           queryset=M.query(),
                                           default_action=None)

        query = filter_set.qs
        self.assertEqual(query.count(), 1)

        search_terms = {'library': None}
        filter_set = ElasticutilsFilterSet(search_fields=self.search_fields,
                                           search_actions=None,
                                           search_terms=search_terms,
                                           mapping_type=self.mapping_type,
                                           queryset=M.query(),
                                           default_action=None)

        query = filter_set.qs
        self.assertEqual(query.count(), 2)

        search_terms = {'category.name': None}
        filter_set = ElasticutilsFilterSet(search_fields=self.search_fields,
                                           search_actions=None,
                                           search_terms=search_terms,
                                           mapping_type=self.mapping_type,
                                           queryset=M.query(),
                                           default_action=None)

        query = filter_set.qs
        self.assertEqual(query.count(), 0)

        article = Article()
        article.author = self.louise
        article.content = 'yo'
        article.subject = 'Article without cathegory'
        article.save()
        # refresh index
        M.refresh_index()

        search_terms = {'category.name': None}
        filter_set = ElasticutilsFilterSet(search_fields=self.search_fields,
                                           search_actions=None,
                                           search_terms=search_terms,
                                           mapping_type=self.mapping_type,
                                           queryset=M.query(),
                                           default_action=None)

        query = filter_set.qs
        self.assertEqual(query.count(), 1)
Exemplo n.º 2
0
    def test_index(self):

        # keep previous indexed objec count
        prev_count = M.count()

        # create an article
        category = Category.objects.create(name='The Tests')

        article1 = Article()
        article1.author = self.florent
        article1.category = category
        article1.content = '!'
        article1.subject = 'make it works'

        article2 = Article()
        article2.author = self.louise
        article2.category = category
        article2.content = 'yo'
        article2.subject = 'My amazing article'

        for i, art in enumerate([article1, article2]):
            # save
            art.save()
            # refresh index
            M.refresh_index()
            # check added
            add_count = M.count()
            self.assertEqual(add_count, prev_count + i + 1)

        for i, a in enumerate([article1, article2]):
            # remove an article
            a.delete()
            # refresh index
            M.refresh_index()
            # check removed
            del_count = M.count()
            self.assertEqual(del_count, add_count - i - 1)