def render(revision_id, documents, encryption_sources=None, cleartext_secrets=False): """Render revision documents for ``revision_id`` using raw ``documents``. :param revision_id: Key used for caching rendered documents by. :type revision_id: int :param documents: List of raw documents corresponding to ``revision_id`` to render. :type documents: List[dict] :param encryption_sources: A dictionary that maps the reference contained in the destination document's data section to the actual unecrypted data. If encrypting data with Barbican, the reference will be a Barbican secret reference. :type encryption_sources: dict :param cleartext_secrets: Whether to show unencrypted data as cleartext. :type cleartext_secrets: bool :returns: Rendered documents for ``revision_id``. :rtype: List[dict] """ # NOTE(felipemonteiro): `validate` is False because documents have # already been pre-validated during ingestion. Documents are # post-validated below, regardless. return cache.lookup_by_revision_id(revision_id, documents, encryption_sources=encryption_sources, validate=False, cleartext_secrets=cleartext_secrets)
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)
def threaded_function(documents): # Validate that caching the ref returns expected payload. rendered_documents, cache_hit = cache.lookup_by_revision_id( 1, documents) rendered_documents_by_thread.append(rendered_documents) cache_hit_by_thread.append(cache_hit)