'Ensure that after caching a result, we always send it back, even if the underlying result changes.'

def test_request_cached_with_caches_despite_changing_wrapped_result(self):

    RequestCache.clear_request_cache()
    to_be_wrapped = Mock()
    to_be_wrapped.side_effect = [1, 2, 3]
    self.assertEqual(to_be_wrapped.call_count, 0)
    def mock_wrapper(*args, **kwargs):
        'Simple    wrapper    to    let    us    decorate    our    mock.'
        return to_be_wrapped(*args, **kwargs)
    wrapped = request_cached(mock_wrapper)
    result = wrapped()
    self.assertEqual(result, 1)
    self.assertEqual(to_be_wrapped.call_count, 1)
    result = wrapped()
    self.assertEqual(result, 1)
    self.assertEqual(to_be_wrapped.call_count, 1)
    direct_result = mock_wrapper()
    self.assertEqual(direct_result, 2)
    self.assertEqual(to_be_wrapped.call_count, 2)
    result = wrapped()
    self.assertEqual(result, 1)
    self.assertEqual(to_be_wrapped.call_count, 2)
    direct_result = mock_wrapper()
    self.assertEqual(direct_result, 3)
    self.assertEqual(to_be_wrapped.call_count, 3)
