def test_B_AssertIfNoQueryableSupplied(self): # [ ] ReviewStateCache asserts if queried before setting conduit cache = phlcon_reviewstatecache.ReviewStateCache() self.assertRaises( AssertionError, cache.get_status, 0) cache = phlcon_reviewstatecache.ReviewStateCache() self.assertRaises( AssertionError, cache.refresh_active_reviews) # [ ] ReviewStateCache asserts if set to no conduit cache = phlcon_reviewstatecache.ReviewStateCache() self.assertRaises( AssertionError, cache.set_conduit, None) # [ ] ReviewStateCache asserts if queried with no conduit set cache = phlcon_reviewstatecache.ReviewStateCache() cache.clear_conduit() self.assertRaises( AssertionError, cache.get_status, 0) cache = phlcon_reviewstatecache.ReviewStateCache() cache.clear_conduit() self.assertRaises( AssertionError, cache.refresh_active_reviews) # [ ] _ReviewStateCache asserts if queried before setting callable cache_impl = phlcon_reviewstatecache._ReviewStateCache() self.assertRaises( AssertionError, cache_impl.get_status, 0) cache_impl = phlcon_reviewstatecache._ReviewStateCache() self.assertRaises( AssertionError, cache_impl.refresh_active_reviews) # [ ] _ReviewStateCache asserts if queried with no callable set cache_impl = phlcon_reviewstatecache._ReviewStateCache() cache_impl.clear_revision_list_status_callable() self.assertRaises( AssertionError, cache_impl.get_status, 0) cache_impl = phlcon_reviewstatecache._ReviewStateCache() cache_impl.clear_revision_list_status_callable() self.assertRaises( AssertionError, cache_impl.refresh_active_reviews)
def test_C_RefreshBeforeGet(self): def fake_callable(revision_list): # [ C] _ReviewStateCache does not callable when refreshing # if no active queries _ = revision_list # NOQA raise Exception("shouldn't get here") # [ C] _ReviewStateCache does not raise if 'refreshed' before any 'get' cache_impl = phlcon_reviewstatecache._ReviewStateCache(fake_callable) cache_impl.refresh_active_reviews()
def test_D_InvalidationRules(self): # [ ] _ReviewStateCache calls out to refresh queries since refresh # [ ] _ReviewStateCache retrieves statuses for reviews not queried revision_list = [101, 1337, 404] expected_queries = [[101], [1337], [404], [101, 1337, 404]] queried_revision_list = [] callable_should_raise = False def fake_callable(actual_revision_list): if callable_should_raise: raise Exception("shouldn't get here") # N.B. we have to assign to the slice as we're in a nested func # and otherwise we won't be referring to the same data # in Python 3 we can do better with nonlocal queried_revision_list[:] = actual_revision_list print queried_revision_list next_expected_query = expected_queries[0] self.assertSetEqual( set(queried_revision_list), set(next_expected_query)) # erase the head of the expected queries list, moving on the next # N.B. we have to assign to the slice as we're in a nested func # and otherwise we won't be referring to the same data # in Python 3 we can do better with nonlocal expected_queries[:] = expected_queries[1:] return [ FakeResult(r, str(r) + 'r', str(r) + 'd') for r in actual_revision_list ] cache_impl = phlcon_reviewstatecache._ReviewStateCache(fake_callable) # exercise getting the state for revision in revision_list: _ = cache_impl.get_state(revision).status # NOQA self.assertNotEqual(set(queried_revision_list), set(revision_list)) cache_impl.refresh_active_reviews() self.assertSetEqual(set(queried_revision_list), set(revision_list)) callable_should_raise = True # [ D] _ReviewStateCache does not callable if queried for cached query # [ D] _ReviewStateCache returns correct value when retrieving cached for revision in revision_list: result = cache_impl.get_state(revision).status self.assertEqual(result, str(revision) + 'r')