def test_get_solr_facet_always_show(self): site_facet = factories.SeoSiteFacetFactory() site = site_facet.seosite settings.SITE_ID = site.pk settings.SITE = site custom_facet = site_facet.customfacet custom_facet.show_production = 1 custom_facet.save() settings.STANDARD_FACET = [custom_facet] # The custom facet should have no results, and therefore should # not be in the list. result_counts = helpers.get_solr_facet([]) self.assertEqual(len(result_counts), 0) custom_facet.always_show = True custom_facet.save() result_counts = helpers.get_solr_facet([]) # If always_show is True the facet should be in the list even # if the count is 0. self.assertEqual(len(result_counts), 1) # The custom facet returned should be the one we created. self.assertEqual(result_counts[0][0], custom_facet) # The count should be 0. self.assertEqual(result_counts[0][1], 0)
def get_custom_facets(request, filters=None, query_string=None): custom_facet_key = get_facet_count_key(filters, query_string) custom_facets = cache.get(custom_facet_key) if not custom_facets: custom_facets = get_solr_facet(settings.SITE_BUIDS, filters=filters, params=request.GET) cache.set(custom_facet_key, custom_facets) return custom_facets