def __init__(self, dep_cache, obj_cache, routes_cache, pod): self._pod = pod self._collection_cache = collection_cache.CollectionCache() self._document_cache = document_cache.DocumentCache() self._file_cache = file_cache.FileCache() self._dependency_graph = dependency.DependencyGraph() self._dependency_graph.add_all(dep_cache) self._object_caches = {} self.create_object_cache(self.KEY_GLOBAL, write_to_file=False, can_reset=True) for key, item in obj_cache.iteritems(): # If this is a string, it is written to a separate cache file. if isinstance(item, basestring): cache_value = {} if self._pod.file_exists(item): cache_value = self._pod.read_json(item) self.create_object_cache(key, **cache_value) else: self.create_object_cache(key, **item) self._routes_cache = grow_routes_cache.RoutesCache() self._routes_cache.from_data(routes_cache)
def test_add_document(self): col_cache = collection_cache.CollectionCache() doc = self.pod.get_doc('/content/pages/intro.md') col = doc.collection col_cache.add_document(doc) self.assertEqual( doc, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe))
def __init__(self, yaml, pod): self._pod = pod self._collection_cache = collection_cache.CollectionCache() self._document_cache = document_cache.DocumentCache() self._dependency_graph = dependency.DependencyGraph() self._dependency_graph.add_all(yaml.get(self.KEY_DEPENDENCIES, {})) self._object_caches = {} self.create_object_cache(self.KEY_GLOBAL, write_to_file=False, can_reset=True) existing_object_caches = yaml.get(self.KEY_OBJECTS, {}) for key, item in existing_object_caches.iteritems(): self.create_object_cache(key, **item)
def __init__(self, dep_cache, obj_cache, pod): self._pod = pod self._collection_cache = collection_cache.CollectionCache() self._document_cache = document_cache.DocumentCache() self._file_cache = file_cache.FileCache() self._dependency_graph = dependency.DependencyGraph() self._dependency_graph.add_all(dep_cache) self._object_caches = {} self.create_object_cache(self.KEY_GLOBAL, write_to_file=False, can_reset=True) existing_object_caches = obj_cache for key, item in existing_object_caches.iteritems(): self.create_object_cache(key, **item)
def test_remove_collection(self): col_cache = collection_cache.CollectionCache() doc = self.pod.get_doc('/content/pages/intro.md') col = doc.collection # Test straight up remove. col_cache.add_collection(col) self.assertEqual(col, col_cache.get_collection('pages')) col_cache.remove_collection(col) self.assertEqual(None, col_cache.get_collection('pages')) # Test that documents in the collection are removed. col_cache.add_document(doc) self.assertEqual( doc, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe)) col_cache.remove_collection(col) self.assertEqual( None, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe))
def test_remove_by_path(self): col_cache = collection_cache.CollectionCache() doc = self.pod.get_doc('/content/pages/intro.md') col = doc.collection col_cache.add_document(doc) # Deleting a document's path removes the document. self.assertEqual( doc, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe)) col_cache.remove_by_path('/content/pages/intro.md') self.assertEqual( None, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe)) # Deleting a collection blueprint removes the entire collection. col_cache.add_collection(col) self.assertEqual(col, col_cache.get_collection('pages')) col_cache.remove_by_path('/content/pages/_blueprint.yaml') self.assertEqual(None, col_cache.get_collection('pages'))
def test_remove_document_locales(self): col_cache = collection_cache.CollectionCache() doc = self.pod.get_doc('/content/pages/intro.md') col_cache.add_document(doc) doc_it = self.pod.get_doc('/content/pages/intro.md', 'it') col_cache.add_document(doc_it) col = doc.collection self.assertEqual( doc, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe)) self.assertEqual( doc_it, col_cache.get_document(col, '/content/pages/intro.md', doc_it.locale_safe)) col_cache.remove_document_locales(doc) self.assertEqual( None, col_cache.get_document(col, '/content/pages/intro.md', doc.locale_safe)) self.assertEqual( None, col_cache.get_document(col, '/content/pages/intro.md', doc_it.locale_safe))
def test_add_collection(self): col_cache = collection_cache.CollectionCache() col = self.pod.get_collection('pages') col_cache.add_collection(col) self.assertEqual(col, col_cache.get_collection('pages'))