@@ -923,7 +923,7 @@ def getCollection(self, collection_url, **kwargs):
923923 in the collection.
924924 """
925925 context = self .contextHelper .currentContext ()
926- # craven ugly hackiness...
926+ # craven ugly hackiness to support calls triggered from within ContextHelper.check ...
927927 if not '?fetch=' in collection_url :
928928 collection_url = "%s?pagesize=%d&start=1" % (collection_url , MAX_PAGESIZE )
929929 resource = collection_url
@@ -943,6 +943,70 @@ def getCollection(self, collection_url, **kwargs):
943943 return rally_rest_response
944944
945945
946+ def addCollectionItems (self , target , items ):
947+ """
948+ Given a target which is a hydrated RallyEntity instance having a valid _type
949+ and a items which is a list of hydrated Rally Entity instances
950+ all of the same _type, construct a valid AC WSAPI collection url and
951+ issue a POST request to that URL supplying the _greased items refs as the
952+ payload.
953+ """
954+ if not items : return None
955+ auth_token = self .obtainSecurityToken ()
956+ target_type = target ._type
957+ item_type = items [0 ]._type
958+ resource = "%s/%s/%ss/add" % (target_type , target .oid , item_type )
959+ collection_url = '%s/%s?fetch=Name&key=%s' % (self .service_url , resource , auth_token )
960+ #print(collection_url)
961+ payload = {"CollectionItems" :[{'_ref' : "%s/%s" % (str (item ._type ), str (item .oid ))}
962+ for item in items ]}
963+ #print(payload)
964+ #print("-------------------------------")
965+ response = self .session .post (collection_url , data = json .dumps (payload ), headers = RALLY_REST_HEADERS )
966+ #print(response.text)
967+ #print(response.reason)
968+ #print(response.content)
969+ context = self .contextHelper .currentContext ()
970+ response = RallyRESTResponse (self .session , context , resource , response , "shell" , 0 )
971+ added_items = [str (item [u'Name' ]) for item in response .data [u'Results' ]]
972+ return added_items
973+
974+ def dropCollectionItems (self , target , items ):
975+ """
976+ Given a target which is a hydrated RallyEntity instance having a valid _type
977+ and a items which is a list of hydrated Rally Entity instances
978+ all of the same _type, construct a valid AC WSAPI collection url and
979+ issue a POST request to that URL supplying the item refs in an appropriate
980+ JSON structure as the payload.
981+ """
982+ if not items : return None
983+ auth_token = self .obtainSecurityToken ()
984+ target_type = target ._type
985+ item_type = items [0 ]._type
986+ resource = "%s/%s/%ss/delete" % (target_type , target .oid , item_type )
987+ collection_url = '%s/%s?key=%s' % (self .service_url , resource , auth_token )
988+ print (collection_url )
989+ payload = {"CollectionItems" :[{'_ref' : "%s/%s" % (str (item ._type ), str (item .oid ))}
990+ for item in items ]}
991+ print (payload )
992+ print ("-------------------------------" )
993+ response = self .session .post (collection_url , data = json .dumps (payload ), headers = RALLY_REST_HEADERS )
994+ print (response .status_code )
995+ print (response .reason )
996+ #print(response.text)
997+ #print(" - - - - - - - - - - - - - - - - - -")
998+ #print(response.content)
999+ print (" - - - - - - - - - - - - - - - - - -" )
1000+ return response .reason
1001+
1002+ #errors = response.errors
1003+ #context = self.contextHelper.currentContext()
1004+ #response = RallyRESTResponse(self.session, context, resource, response, "shell", 0)
1005+ #errors = [item[u'Errors'] for item in response.data[u'OperationResult']]
1006+ #errors = [item[u'Errors'] for item in response.data[u'QueryResult']]
1007+ #return errors
1008+
1009+
9461010 def put (self , entityName , itemData , workspace = 'current' , project = 'current' , ** kwargs ):
9471011 """
9481012 Given a Rally entityName, a dict with data that the newly created entity should contain,
0 commit comments