Esempio n. 1
0
    def test_uses_cache_on_hit(self):
        """Ensure that we actually do use the cache when available."""
        # put it in the cache
        fallback = mock.Mock(return_value='asdf')
        cache_lookup_with_fallback('key', fallback)
        fallback.assert_called_once_with()

        # retrieve from cache
        fallback2 = mock.Mock(return_value='gggg')
        result = cache_lookup_with_fallback('key', fallback2)
        fallback2.assert_not_called()
        assert result == fallback.return_value
Esempio n. 2
0
    def test_uses_cache_on_hit(self):
        """Ensure that we actually do use the cache when available."""
        # put it in the cache
        fallback = mock.Mock(return_value='asdf')
        cache_lookup_with_fallback('key', fallback)
        fallback.assert_called_once_with()

        # retrieve from cache
        fallback2 = mock.Mock(return_value='gggg')
        result = cache_lookup_with_fallback('key', fallback2)
        fallback2.assert_not_called()
        assert result == fallback.return_value
Esempio n. 3
0
 def test_evaluates_fallback_on_miss(self):
     """Ensure that if we miss, we call the fallback."""
     fallback = mock.Mock(return_value='asdf')
     result = cache_lookup_with_fallback('key', fallback)
     fallback.assert_called_once_with()
     assert result == fallback.return_value
Esempio n. 4
0
 def test_evaluates_fallback_on_miss(self):
     """Ensure that if we miss, we call the fallback."""
     fallback = mock.Mock(return_value='asdf')
     result = cache_lookup_with_fallback('key', fallback)
     fallback.assert_called_once_with()
     assert result == fallback.return_value