class TestBaseSuggestionEngine(TestCase):
    def setUp(self):
        self.instance = BaseSuggestionEngine(QUERY)

    def test_init(self):
        eq_(self.instance.query, QUERY)

    def test_fetch(self):
        with self.assertRaises(NotImplementedError):
            self.instance.fetch(self.instance.query)

    def test_sanitize(self):
        eq_(self.instance.sanitize(RESULTS), RESULTS)

    @patch('app.search.suggest.base.BaseSuggestionEngine.fetch')
    @patch('app.memorize.memcached', mock_memcached)
    def test_search(self, mock_fetch):
        mock_fetch.return_value = RESULTS
        results_cold = self.instance.search(QUERY)
        results_warm = self.instance.search(QUERY)
        ok_(not results_cold.from_cache)
        ok_(results_warm.from_cache)
        eq_(results_cold.cache_key, results_warm.cache_key)
        eq_(results_cold, results_warm, RESULTS)
Exemple #2
0
class TestBaseSuggestionEngine(TestCase):
    def setUp(self):
        self.instance = BaseSuggestionEngine(QUERY)

    def test_init(self):
        eq_(self.instance.query, QUERY)

    def test_fetch(self):
        with self.assertRaises(NotImplementedError):
            self.instance.fetch(self.instance.query)

    def test_sanitize(self):
        eq_(self.instance.sanitize(RESULTS), RESULTS)

    @patch('app.search.suggest.base.BaseSuggestionEngine.fetch')
    @patch('app.memorize.memcached', mock_memcached)
    def test_search(self, mock_fetch):
        mock_fetch.return_value = RESULTS
        results_cold = self.instance.search(QUERY)
        results_warm = self.instance.search(QUERY)
        ok_(not results_cold.from_cache)
        ok_(results_warm.from_cache)
        eq_(results_cold.cache_key, results_warm.cache_key)
        eq_(results_cold, results_warm, RESULTS)
 def setUp(self):
     self.instance = BaseSuggestionEngine(QUERY)
Exemple #4
0
 def setUp(self):
     self.instance = BaseSuggestionEngine(QUERY)