def test_filter_nested(self): search_terms = {'contributors': ['louise']} 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) filters = query.build_search() self.assertEqual(filters['filter'], filter_set._get_filter_nested_item('contributors', 'louise')) # noqa search_terms = {'contributors': ['louise', 'florent']} 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)
def test_filter_term_string(self): search_terms = {'subject': 'amazing'} 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) # Test formed filter subject_filter = filter_set.get_filter('subject', 'amazing').__repr__() self.assertEqual(F(**{'subject': 'amazing'}).__repr__(), subject_filter) # noqa filtered_qs = filter_set.qs self.assertEqual(filtered_qs.count(), 1)
def test_filter_prefix_or_startswith(self): default_action = 'prefix' search_terms = {'category.name': 'tes'} 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=default_action) self.assertEqual(filter_set.qs.count(), 2) search_actions = {'category.name': 'prefix'} filter_set = ElasticutilsFilterSet(search_fields=self.search_fields, search_actions=search_actions, search_terms=search_terms, mapping_type=self.mapping_type, queryset=M.query(), default_action=None) subject_filter = filter_set.get_filter('category.name', 'tes').__repr__() # noqa self.assertEqual(F(**{'category.name__prefix': 'tes'}).__repr__(), subject_filter) # noqa default_action = 'startswith' search_terms = {'category.name': 'tes'} 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=default_action) self.assertEqual(filter_set.qs.count(), 2) self.assertEqual(filter_set.count, 2) search_actions = {'category.name': 'startswith'} filter_set = ElasticutilsFilterSet(search_fields=self.search_fields, search_actions=search_actions, search_terms=search_terms, mapping_type=self.mapping_type, queryset=M.query(), default_action='prefix') self.assertEqual(filter_set.qs.count(), 2) self.assertEqual(filter_set.count, 2) subject_filter = filter_set.get_filter('category.name', 'tes').__repr__() # noqa self.assertEqual(F(**{'category.name__startswith': 'tes'}).__repr__(), subject_filter) # noqa