def test_autocompleter_with_facet_and_non_facet_providers(self):
        """
        Autocompleter with facet and non-facet providers works correctly
        """
        registry.set_autocompleter_setting('facet_stock_no_facet_ind', 'MAX_RESULTS', 100)
        facets = [
            {
                'type': 'and',
                'facets': [{'key': 'sector', 'value': 'Financial Services'}]
            }
        ]
        matches = self.autocomp.suggest('a')
        facet_matches = self.autocomp.suggest('a', facets=facets)

        # because we are using the faceted stock provider in the 'facet_stock_no_facet_ind' AC,
        # we expect using facets will decrease the amount of results when searching.
        self.assertEqual(len(matches['faceted_stock']), 25)
        self.assertEqual(len(facet_matches['faceted_stock']), 2)

        # since the indicator provider does not support facets,
        # we expect the search results from both a facet and non-facet search to be the same.
        self.assertEqual(len(matches['ind']), 16)
        self.assertEqual(len(matches['ind']), len(facet_matches['ind']))

        registry.del_autocompleter_setting('facet_stock_no_facet_ind', 'MAX_RESULTS')
 def test_move_exact_matches_multi_provider_autocompleter_setting(self):
     """
     MOVE_EXACT_MATCHES_TO_TOP works in multi-provider autocompleter at autocompleter level
     """
     matches = self.autocomp.suggest('Ma')
     registry.set_autocompleter_setting(self.autocomp.name, 'MOVE_EXACT_MATCHES_TO_TOP', True)
     matches2 = self.autocomp.suggest('Ma')
     registry.del_autocompleter_setting(self.autocomp.name, 'MOVE_EXACT_MATCHES_TO_TOP')
     self.assertNotEqual(matches['stock'][0]['search_name'], matches2['stock'][0]['search_name'])
 def test_move_exact_matches_overridable_at_ac_level(self):
     """
     MOVE_EXACT_MATCHES_TO_TOP can be set at the autocompleter level
     """
     matches = self.autocomp.suggest('Ma')
     registry.set_autocompleter_setting(self.autocomp.name, 'MOVE_EXACT_MATCHES_TO_TOP', True)
     matches2 = self.autocomp.suggest('Ma')
     registry.del_autocompleter_setting(self.autocomp.name, 'MOVE_EXACT_MATCHES_TO_TOP')
     self.assertNotEqual(matches[0]['search_name'], matches2[0]['search_name'])
    def test_max_results_has_hard_limit(self):
        """
        Suggest respects MAX_RESULTS over giving every provider at least 1 result
        """
        registry.set_autocompleter_setting('ind_stock', 'MAX_RESULTS', 1)
        matches = self.autocomp.suggest('a')
        # Either stock or indicator matches is empty
        self.assertEqual(1, len(matches['stock']) + len(matches['ind']))

        registry.del_autocompleter_setting('ind_stock', 'MAX_RESULTS')
    def test_max_results_spreads_results_evenly(self):
        """
        MAX_RESULTS spreads the results among providers equally
        """
        registry.set_autocompleter_setting('ind_stock', 'MAX_RESULTS', 4)
        matches = self.autocomp.suggest('a')
        self.assertEqual(4, len(matches['stock']) + len(matches['ind']))
        self.assertEqual(len(matches['stock']), len(matches['ind']))

        registry.del_autocompleter_setting('ind_stock', 'MAX_RESULTS')
    def test_max_results_handles_surplus(self):
        """
        Suggest respects MAX_RESULTS while still dealing with surplus
        """
        # we know that there are 16 ind matches and 25 stock matches for 'a'
        registry.set_autocompleter_setting('ind_stock', 'MAX_RESULTS', 36)
        matches = self.autocomp.suggest('a')
        self.assertEqual(16, len(matches['ind']))
        self.assertEqual(20, len(matches['stock']))

        registry.del_autocompleter_setting('ind_stock', 'MAX_RESULTS')
Example #7
0
 def test_move_exact_matches_multi_provider_autocompleter_setting(self):
     """
     MOVE_EXACT_MATCHES_TO_TOP works in multi-provider autocompleter at autocompleter level
     """
     matches = self.autocomp.suggest('Ma')
     registry.set_autocompleter_setting(self.autocomp.name,
                                        'MOVE_EXACT_MATCHES_TO_TOP', True)
     matches2 = self.autocomp.suggest('Ma')
     registry.del_autocompleter_setting(self.autocomp.name,
                                        'MOVE_EXACT_MATCHES_TO_TOP')
     self.assertNotEqual(matches['stock'][0]['search_name'],
                         matches2['stock'][0]['search_name'])
Example #8
0
 def test_move_exact_matches_overridable_at_ac_level(self):
     """
     MOVE_EXACT_MATCHES_TO_TOP can be set at the autocompleter level
     """
     matches = self.autocomp.suggest('Ma')
     registry.set_autocompleter_setting(self.autocomp.name,
                                        'MOVE_EXACT_MATCHES_TO_TOP', True)
     matches2 = self.autocomp.suggest('Ma')
     registry.del_autocompleter_setting(self.autocomp.name,
                                        'MOVE_EXACT_MATCHES_TO_TOP')
     self.assertNotEqual(matches[0]['search_name'],
                         matches2[0]['search_name'])
    def test_ac_specific_max_results_setting(self):
        """
        Autocompleter specific MAX_RESULTS is respected
        """
        matches = self.autocomp.suggest('a')
        self.assertEqual(len(matches), 10)

        registry.set_autocompleter_setting('stock', 'MAX_RESULTS', 5)
        matches = self.autocomp.suggest('a')
        self.assertEqual(len(matches), 5)

        # Must set the setting back to where it was as it will persist
        registry.del_autocompleter_setting('stock', 'MAX_RESULTS')
    def test_max_results_handles_deficit_less_than_surplus(self):
        """
        MAX_RESULTS stops trying to hand out surplus matches when provider's deficits are met
        """
        # Previous code would have failed on this test case because of an infinite while loop that
        # failed to break when all provider's deficits were met. The setup requires
        # there to be at least one provider which will have a deficit less than the total surplus.
        # In this test case, the total surplus will be 3 (since stock has no matches) and the deficit
        # for indicators will be 2 (since there are 5 total matches for indicators and 3 slots are
        # reserved initially)
        registry.set_autocompleter_setting('ind_stock', 'MAX_RESULTS', 6)
        matches = self.autocomp.suggest('S&P')
        self.assertEqual(5, len(matches['ind']))
        self.assertEqual(0, len(matches['stock']))

        registry.del_autocompleter_setting('ind_stock', 'MAX_RESULTS')
    def test_max_results_respected(self):
        """
        MAX_RESULTS is respected for multi-type search case
        """
        # set MAX_RESULTS to an arbitrarily large number
        registry.set_autocompleter_setting('ind_stock', 'MAX_RESULTS', 100)

        matches = self.autocomp.suggest('a')
        total_matches_with_large_max_results = len(matches['stock']) + len(matches['ind'])
        self.assertGreaterEqual(100, total_matches_with_large_max_results)
        self.assertEqual(41, total_matches_with_large_max_results)

        registry.set_autocompleter_setting('ind_stock', 'MAX_RESULTS', 4)
        matches = self.autocomp.suggest('a')
        total_matches_with_small_max_results = len(matches['stock']) + len(matches['ind'])
        self.assertEqual(4, total_matches_with_small_max_results)

        self.assertGreater(total_matches_with_large_max_results, total_matches_with_small_max_results)

        registry.del_autocompleter_setting('ind_stock', 'MAX_RESULTS')