def test_get_not_found_community_collections(self): """ Test retrieving all collections from an especific not found community """ dspace = self.dspace test_id = -1 self.assertRaises(Community.DoesNotExist,lambda:Community.get_collections(dspace,test_id,expand=["parentCommunity"]))
def test_get_all_communities(self): """ Test Retrieving all communities """ dspace= self.dspace communities = Community.get_all(dspace) self.assertGreater(len(communities),0)
def test_get_community(self): """ Test Retrieving an community by Id """ dspace= self.dspace test_id = 2 community = Community.get_community(dspace,test_id) self.assertEqual(community.id,test_id,"Get community by Id Fails")
def test_get_all_communities_with_limit(self): """ Test Retrieving all communities with limit """ dspace= self.dspace max_communities = 5 communities = Community.get_all(dspace,limit=[max_communities]) self.assertLessEqual(len(communities),max_communities)
def get_collections_by_community(request,id): """ Return all collections of the specified community. """ try: collections = Community.get_collections(dspace,id,**dict(request.query_params)) return Response(collections, status=status.HTTP_200_OK) except Community.DoesNotExist: raise Http404
def test_get_top_communities(self): """ Test retrieving top level communities """ dspace = self.dspace communities = Community.get_top_communities(dspace,expand=["parentCommunity"]) self.assertIsNotNone(communities) for com in communities: self.assertIsNone(com['parentCommunity'])
def test_get_community_collections(self): """ Test retrieving all collections from an especific community """ dspace = self.dspace test_id = 2 collections = Community.get_collections(dspace,test_id,expand=["parentCommunity"]) self.assertIsNotNone(collections) for collection in collections: collection_temp = Collection(dict(collection)) self.assertEqual(test_id,collection_temp.parentCommunity["id"])
def get_top_communities(request): """ Return top level communities array """ communities = Community.get_top_communities(dspace,**dict(request.query_params)) return Response(communities,status=status.HTTP_200_OK)
def get_object(self,id,**kwargs): try: community = Community.get_community(dspace,id,**dict(kwargs)) return community except Community.DoesNotExist: raise Http404
def get(self,request,*args,**kwargs): communities = Community.get_all(dspace,**dict(self.request.query_params)) return Response(communities, status=status.HTTP_200_OK)