Пример #1
0
    def test_lookup_by_revision_id_cache(self):
        """Validate ``lookup_by_revision_id`` caching works.

        Passing in None in lieu of the actual documents proves that:

        * if the payload is in the cache, then no error is thrown since the
          cache is hit so no further processing is performed, where otherwise a
          method would be called on `None`
        * if the payload is not in the cache, then following logic above,
          method is called on `None`, raising AttributeError
        """

        document_factory = factories.DocumentFactory(1, [1])
        documents = document_factory.gen_test({})

        # Validate that caching the ref returns expected payload.
        rendered_documents = cache.lookup_by_revision_id(1, documents)
        self.assertIsInstance(rendered_documents, list)

        # Validate that the cache actually works.
        next_rendered_documents = cache.lookup_by_revision_id(1, None)
        self.assertEqual(rendered_documents, next_rendered_documents)

        # No documents passed in and revision ID 2 isn't cached - so expect
        # this to blow up.
        with testtools.ExpectedException(AttributeError):
            cache.lookup_by_revision_id(2, None)

        # Invalidate the cache and ensure the original data isn't there.
        cache.invalidate()

        # The cache won't be hit this time - expect AttributeError.
        with testtools.ExpectedException(AttributeError):
            cache.lookup_by_revision_id(1, None)
Пример #2
0
def invalidate_cache_data():
    """Invalidate all data associated with document rendering."""
    barbican_cache.invalidate()
    engine_cache.invalidate()
Пример #3
0
 def tearDown(self):
     # Clear the cache between tests.
     cache.invalidate()
     super(DeckhandTestCase, self).tearDown()