def test_get_not_found_collection_items(self): """ Test retrieving all items from an especific not found collection """ dspace = self.dspace test_id = -1 self.assertRaises(Collection.DoesNotExist,lambda:Collection.get_items(dspace,test_id,expand=["parentCollection"]))
def test_get_all_collections(self): """ Test Retrieving all collections """ dspace= self.dspace collections = Collection.get_all(dspace) self.assertGreater(len(collections),0)
def test_get_community(self): """ Test Retrieving an collection by Id """ dspace= self.dspace test_id = 2 collection = Collection.get_collection(dspace,test_id) self.assertEqual(collection.id,test_id,"Get collection by Id Fails")
def test_get_all_collections_with_limit(self): """ Test Retrieving all collections with limit """ dspace= self.dspace max_collections = 5 collections = Collection.get_all(dspace,limit=[max_collections]) self.assertLessEqual(len(collections),max_collections)
def get_items_by_collection(request,id): """ Return all items of the specified collection. """ try: items = Collection.get_items(dspace,id,**dict(request.query_params)) return Response(items, status=status.HTTP_200_OK) except Collection.DoesNotExist: raise Http404
def test_get_collection_items(self): """ Test retrieving all items from an especific collection """ dspace = self.dspace test_id = 2 items = Collection.get_items(dspace,test_id,expand=["parentCollection"]) self.assertIsNotNone(items) for item in items: item_temp = Item(dict(item)) self.assertEqual(test_id,item_temp.parentCollection["id"])
def get_object(self,id,**kwargs): try: collection = Collection.get_collection(dspace,id,**dict(kwargs)) return collection except Collection.DoesNotExist: raise Http404
def get(self,request,*args,**kwargs): collections = Collection.get_all(dspace,**dict(self.request.query_params)) return Response(collections, status=status.HTTP_200_OK)