def test_category_filters_are_available(self): self.request_args.setlist('serviceCategories', ['accounting and finance']) search_summary = SearchSummary('9', self.request_args, g9_filter_groups, self._g9_lots_by_slug) summary_markup = search_summary.markup() assert "category <strong>Accounting and finance</strong>" in summary_markup
def test_markup_method_works_with_no_fragments(self): def get_starting_sentence(): return u"5 results found" search_summary = SearchSummary(9, self.request_args, filter_groups, self._lots_by_slug) search_summary.get_starting_sentence = get_starting_sentence search_summary.filters_fragments = [] assert search_summary.markup() == u"5 results found"
def test_markup_method_works_with_wrap(self): def get_starting_sentence(): return u"5 results found" search_summary = SearchSummary(9, self.request_args, filter_groups, self._lots_by_slug) search_summary.get_starting_sentence = get_starting_sentence search_summary.filters_fragments = [] wrapped_summary_markup = search_summary.markup(True) assert wrapped_summary_markup == u'<p class="app-search-summary govuk-body-s">5 results found</p>'
def test_markup_method_works_with_fragments(self): def get_starting_sentence(): return u"5 results found" fragment = Mock(**{"str.return_value": u"with option1 and option2"}) search_summary = SearchSummary(9, self.request_args, filter_groups, self._lots_by_slug) search_summary.get_starting_sentence = get_starting_sentence search_summary.filters_fragments = [fragment] assert search_summary.markup( ) == u"5 results found with option1 and option2"
def test_mix_boolean_and_radio_filters(self): """ Test for a bug where a radio button's filter summary would replace (rather than add to) the summary for a boolean, in the same filter group. """ self.request_args.setlist('phoneSupport', ['true']) self.request_args.setlist('emailOrTicketingSupport', ['yes']) search_summary = SearchSummary('9', self.request_args, g9_filter_groups, self._g9_lots_by_slug) summary_markup = search_summary.markup() assert "email or online ticketing" in summary_markup assert "phone" in summary_markup
def test_mixed_radios_with_identical_values(self): """ Test for a bug where two radio buttons (from different questions, but in the same filter group) with the same value would overwrite each other's summary, rather than combine together correctly. """ self.request_args.setlist('webChatSupport', ['yes']) self.request_args.setlist('emailOrTicketingSupport', ['yes']) search_summary = SearchSummary('9', self.request_args, g9_filter_groups, self._g9_lots_by_slug) summary_markup = search_summary.markup() assert "web chat" in summary_markup assert "email or online ticketing" in summary_markup
def test_each_filter(self): """ Test each filter individually adds a single text string to the summary text """ for lot in self._g9_lots_by_slug: self.request_args['lot'] = lot for filter_group in g9_filter_groups: for f in filter_group['filters']: request_args = self.request_args.copy() request_args[f['name']] = f['value'] search_summary = SearchSummary('9', request_args, g9_filter_groups, self._g9_lots_by_slug) summary_markup = search_summary.markup() assert summary_markup.count( "<strong>" ) == 3 # the keyword, the lot, and one filter
def test_all_filters(self): """ Incrementally add filters, so if there's one that doesn't seem to work in conjunction with the others, we find it. """ for lot in self._g9_lots_by_slug: self.request_args['lot'] = lot filter_count = 0 request_args = self.request_args.copy( ) # reset all filters for a new lot for filter_group in g9_filter_groups: for f in filter_group['filters']: request_args.add(f['name'], f['value']) filter_count += 1 search_summary = SearchSummary('9', request_args, g9_filter_groups, self._g9_lots_by_slug) summary_markup = search_summary.markup() assert summary_markup.count("<strong>") == 2 + filter_count
def test_subcategory_filters_are_available(self): self.request_args.setlist('serviceCategories', ['analytics']) search_summary = SearchSummary('9', self.request_args, g9_filter_groups, self._g9_lots_by_slug) summary_markup = search_summary.markup() assert "category <strong>Analytics</strong>" in summary_markup