def test_delete_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.delete(p1) ec_return = ec.delete(p1) assert backend_return == ec_return
def test_delete_fail(self): cache_storage = MemoryStorage() back_storage = MemoryStorage() ec = EnfoldCache(back_storage, cache=cache_storage) p1 = Policy(1, description='foo') p2 = Policy(2, description='bar') ec.add(p1) ec.add(p2) back_storage.delete = Mock(side_effect=Exception('error!')) with pytest.raises(Exception) as excinfo: ec.delete(2) assert 'error!' == str(excinfo.value) assert [p1, p2] == back_storage.get_all(1000, 0) assert [p1, p2] == cache_storage.get_all(1000, 0)