def test_init(self): library = self._default_library default_collection = self._default_collection other_collection = self._collection() other_collection_2 = self._collection() # A lane for all the collections associated with a library. lane = CrawlableCollectionBasedLane(library) eq_("Crawlable feed: %s" % library.name, lane.display_name) eq_([x.id for x in library.collections], lane.collection_ids) # A lane for a collection not actually associated with a # library. lane = CrawlableCollectionBasedLane( None, [other_collection, other_collection_2] ) eq_( "Crawlable feed: %s / %s" % tuple( sorted([other_collection.name, other_collection_2.name]) ), lane.display_name ) eq_(set([other_collection.id, other_collection_2.id]), set(lane.collection_ids)) eq_(None, lane.get_library(self._db))
def test_init(self): # Collection-based crawlable feeds are cached for 2 hours. eq_(2 * 60 * 60, CrawlableCollectionBasedLane.MAX_CACHE_AGE) # This library has two collections. library = self._default_library default_collection = self._default_collection other_library_collection = self._collection() library.collections.append(other_library_collection) # This collection is not associated with any library. unused_collection = self._collection() # A lane for all the collections associated with a library. lane = CrawlableCollectionBasedLane() lane.initialize(library) eq_("Crawlable feed: %s" % library.name, lane.display_name) eq_(set([x.id for x in library.collections]), set(lane.collection_ids)) # A lane for specific collection, regardless of their library # affiliation. lane = CrawlableCollectionBasedLane() lane.initialize([unused_collection, other_library_collection]) eq_( "Crawlable feed: %s / %s" % tuple( sorted([unused_collection.name, other_library_collection.name ])), lane.display_name) eq_(set([unused_collection.id, other_library_collection.id]), set(lane.collection_ids)) # Unlike pretty much all other lanes in the system, this lane # has no affiliated library. eq_(None, lane.get_library(self._db))
def test_url_arguments(self): library = self._default_library other_collection = self._collection() # A lane for all the collections associated with a library. lane = CrawlableCollectionBasedLane(library) route, kwargs = lane.url_arguments eq_(CrawlableCollectionBasedLane.LIBRARY_ROUTE, route) eq_(None, kwargs.get("collection_name")) # A lane for a collection not actually associated with a # library. (A Library is still necessary to provide a point of # reference for classes like Facets and CachedFeed.) lane = CrawlableCollectionBasedLane(library, [other_collection]) route, kwargs = lane.url_arguments eq_(CrawlableCollectionBasedLane.COLLECTION_ROUTE, route) eq_(other_collection.name, kwargs.get("collection_name"))
def test_bibliographic_filter_clause(self): # Normally, if collection_ids is empty it means there are no # restrictions on collection. However, in this case if # collections_id is empty it means no titles should be # returned. collection = self._default_collection self._default_library.collections = [] lane = CrawlableCollectionBasedLane(self._default_library) eq_([], lane.collection_ids) # This is managed by having bibliographic_filter_clause return None # to short-circuit a query in progress. eq_((None, None), lane.bibliographic_filter_clause(object(), object())) # If collection_ids is not empty, then # bibliographic_filter_clause passed through the query it's # given without changing it. lane.collection_ids = [self._default_collection.id] qu = self._db.query(MaterializedWorkWithGenre) qu2, clause = lane.bibliographic_filter_clause(self._db, qu) eq_(qu, qu2) eq_(None, clause)
def test_url_arguments(self): library = self._default_library other_collection = self._collection() # A lane for all the collections associated with a library. lane = CrawlableCollectionBasedLane() lane.initialize(library) route, kwargs = lane.url_arguments assert CrawlableCollectionBasedLane.LIBRARY_ROUTE == route assert None == kwargs.get("collection_name") # A lane for a collection not actually associated with a # library. lane = CrawlableCollectionBasedLane() lane.initialize([other_collection]) route, kwargs = lane.url_arguments assert CrawlableCollectionBasedLane.COLLECTION_ROUTE == route assert other_collection.name == kwargs.get("collection_name")