def test_get_for_non_populated_cache(self, log_mock): cache_storage = MemoryStorage() back_storage = MemoryStorage() p1 = Policy(1, description='foo') p2 = Policy(2, description='bar') back_storage.add(p1) back_storage.add(p2) ec = EnfoldCache(back_storage, cache=cache_storage, populate=False) assert p1 == ec.get(1) log_mock.warning.assert_called_with( '%s cache miss for get Policy with UID=%s. Trying to get it from backend storage', 'EnfoldCache', 1) log_mock.reset_mock() assert p2 == ec.get(2) assert 1 == log_mock.warning.call_count log_mock.reset_mock() # test we won't return any inexistent policies assert ec.get(3) is None
def test_get_return_value(self): cache_storage = MemoryStorage() back_storage = MemoryStorage() ec = EnfoldCache(back_storage, cache=cache_storage) p1 = Policy(1) ec.add(p1) backend_return = back_storage.get(1) ec_return = ec.get(1) assert backend_return == ec_return