Exemplo n.º 1
0
 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
Exemplo n.º 2
0
 def test_search_summary_works_with_blank_keywords(self):
     self.request_args.setlist('q', [''])
     search_summary = SearchSummary('1', self.request_args, filter_groups,
                                    self._lots_by_slug)
     assert search_summary.count == '1'
     assert search_summary.sentence == u"result found in <strong>Software as a Service</strong>"
     assert len(search_summary.filters_fragments) == 0
Exemplo n.º 3
0
 def test_search_summary_works_with_keywords(self):
     search_summary = SearchSummary('1', self.request_args, filter_groups,
                                    self._lots_by_slug)
     assert search_summary.count == '1'
     assert search_summary.sentence == (
         u"result found containing <strong>email</strong> in "
         "<strong>Software as a Service</strong>")
     assert len(search_summary.filters_fragments) == 0
Exemplo n.º 4
0
    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"
Exemplo n.º 5
0
 def test_search_summary_works_with_a_different_lot(self):
     self.request_args.setlist('lot', ['iaas'])
     search_summary = SearchSummary('1', self.request_args, filter_groups,
                                    self._lots_by_slug)
     assert search_summary.count == '1'
     assert search_summary.sentence == (
         u"result found containing <strong>email</strong> in <strong>Infrastructure as a Service</strong>"
     )
     assert len(search_summary.filters_fragments) == 0
Exemplo n.º 6
0
 def test_search_summary_with_a_single_filter_group(self):
     self.request_args.setlist('serviceTypes', ['collaboration'])
     search_summary = SearchSummary('9', self.request_args, filter_groups,
                                    self._lots_by_slug)
     assert search_summary.count == '9'
     assert search_summary.sentence == (
         u"results found containing <strong>email</strong> in <strong>Software as a Service</strong>"
     )
     assert len(search_summary.filters_fragments) == 1
Exemplo n.º 7
0
    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>'
Exemplo n.º 8
0
    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"
Exemplo n.º 9
0
 def test_get_starting_sentence_works(self):
     search_summary = SearchSummary('9', self.request_args, filter_groups,
                                    self._lots_by_slug)
     search_summary.count = '9'
     search_summary.COUNT_PRE_TAG = '<strong>'
     search_summary.COUNT_POST_TAG = '</strong>'
     search_summary.sentence = (
         u"results found containing <strong>email</strong>" +
         u" in <strong>Software as a Service</strong>")
     assert search_summary.get_starting_sentence() == (
         u"<strong>9</strong> results found containing "
         "<strong>email</strong> in <strong>Software as a Service</strong>")
Exemplo n.º 10
0
 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
Exemplo n.º 11
0
 def test_search_summary_with_two_filter_groups(self):
     self.request_args.setlist('serviceTypes',
                               ['collaboration', 'energy and environment'])
     self.request_args.setlist(
         'datacentreTier', ['tia-942 tier 1', 'uptime institute tier 1'])
     search_summary = SearchSummary('9', self.request_args, filter_groups,
                                    self._lots_by_slug)
     assert search_summary.count == '9'
     assert search_summary.sentence == (
         u"results found containing <strong>email</strong> in <strong>Software as a Service</strong>"
     )
     assert len(search_summary.filters_fragments) == 2
Exemplo n.º 12
0
 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
Exemplo n.º 13
0
 def test_search_summary_orders_filter_groups_as_in_manifest(self):
     self.request_args.setlist('serviceTypes',
                               ['collaboration', 'energy and environment'])
     self.request_args.setlist(
         'datacentreTier', ['tia-942 tier 1', 'uptime institute tier 1'])
     self.request_args.setlist('freeOption', ['true'])
     self.request_args.setlist('trialOption', ['true'])
     search_summary = SearchSummary('9', self.request_args, filter_groups,
                                    self._lots_by_slug)
     correct_order = ['Categories', 'Pricing', 'Datacentre tier']
     order_of_groups_of_filters = [
         fragment.id for fragment in search_summary.filters_fragments
     ]
     assert order_of_groups_of_filters == correct_order
Exemplo n.º 14
0
 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
Exemplo n.º 15
0
    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 __init__(self,
                 search_api_client,
                 search_api_url,
                 frameworks_by_slug,
                 include_markup=False):
        # Get core data
        self.framework_slug = search_api_client.get_index_from_search_api_url(
            search_api_url)
        framework = frameworks_by_slug[self.framework_slug]
        content_manifest = content_loader.get_manifest(
            self.framework_slug, 'services_search_filters')
        lots_by_slug = get_lots_by_slug(framework)

        # We need to get buyer-frontend query params from our saved search API URL.
        search_query_params = search_api_client.get_frontend_params_from_search_api_url(
            search_api_url)
        search_query_params = ungroup_request_filters(search_query_params,
                                                      content_manifest)
        search_query_params_multidict = MultiDict(search_query_params)

        current_lot_slug = search_query_params_multidict.get('lot', None)
        filters = filters_for_lot(current_lot_slug,
                                  content_manifest,
                                  all_lots=framework['lots'])
        clean_request_query_params = clean_request_args(
            search_query_params_multidict, filters.values(), lots_by_slug)

        # Now build the buyer-frontend URL representing the saved Search API URL
        self.url = construct_url_from_base_and_params(
            url_for('main.search_services'), search_query_params)

        # Get the saved Search API URL result set and build the search summary.
        search_api_response = search_api_client._get(search_api_url)
        self.search_summary = SearchSummary(
            search_api_response['meta']['total'],
            clean_request_query_params.copy(), filters.values(), lots_by_slug)
Exemplo n.º 17
0
 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