Skip to content

Commit 08cff9f

Browse files
committed
minor formatting and style mods in restapi.py
1 parent 65791ff commit 08cff9f

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

pyral/restapi.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
###################################################################################################
44
#
55
# pyral.restapi - Python Rally REST API module
6-
# round 13 first stab at support for Python 3.5 or higher
6+
# round 14 support for multi-element-path Project names, couple of minor defect fixes
77
# notable dependencies:
88
# requests v2.8.1 or better
99
#
@@ -325,6 +325,7 @@ def serviceURL(self):
325325
"""
326326
return self.service_url
327327

328+
328329
def obtainSecurityToken(self):
329330
if self.apikey:
330331
return None
@@ -395,12 +396,14 @@ def disableWarnings(self):
395396
def warningsEnabled(self):
396397
return self._warn == True
397398

399+
398400
def subscriptionName(self):
399401
"""
400402
Returns the name of the subscription in the currently active context.
401403
"""
402404
return self.contextHelper.currentContext().subscription()
403405

406+
404407
def setWorkspace(self, workspaceName):
405408
"""
406409
Given a workspaceName, set that as the currentWorkspace and use the ref for
@@ -415,6 +418,7 @@ def setWorkspace(self, workspaceName):
415418
raise Exception('Specified workspace not valid for your credentials or is in a Closed state')
416419
self.contextHelper.setWorkspace(workspaceName)
417420

421+
418422
def getWorkspace(self):
419423
"""
420424
Returns a minimally hydrated Workspace instance with the Name and ref
@@ -424,6 +428,7 @@ def getWorkspace(self):
424428
wksp_name, wksp_ref = self.contextHelper.getWorkspace()
425429
return _createShellInstance(context, 'Workspace', wksp_name, wksp_ref)
426430

431+
427432
def getWorkspaces(self):
428433
"""
429434
Return a list of minimally hydrated Workspace instances
@@ -609,7 +614,8 @@ def getAllUsers(self, workspace=None):
609614
# and other UserProfile attributes
610615
]
611616

612-
users_resource = 'users?fetch=%s&query=&pagesize=%s&start=1&workspace=%s' % (",".join(user_attrs), MAX_PAGESIZE, workspace_ref)
617+
users_resource = 'users?fetch=%s&query=&pagesize=%s&start=1&workspace=%s' % \
618+
(",".join(user_attrs), MAX_PAGESIZE, workspace_ref)
613619
full_resource_url = '%s/%s' % (self.service_url, users_resource)
614620
response = self.session.get(full_resource_url, timeout=SERVICE_REQUEST_TIMEOUT)
615621
if response.status_code != HTTP_REQUEST_SUCCESS_CODE:
@@ -939,7 +945,6 @@ def get(self, entity, fetch=False, query=None, order=None, **kwargs):
939945
##
940946
## print("full_resource_url: %s" % full_resource_url)
941947
##
942-
943948
if self._log:
944949
# unquote the resource for enhanced readability
945950
self._logDest.write('%s GET %s\n' % (timestamp(), unquote(resource)))
@@ -1033,7 +1038,7 @@ def post(self, entityName, itemData, workspace='current', project='current', **k
10331038
if not oid:
10341039
formattedID = itemData.get('FormattedID', None)
10351040
if not formattedID:
1036-
raise RallyRESTAPIError('An identifying field (Object or FormattedID) must be specified')
1041+
raise RallyRESTAPIError('An identifying field (ObjectID or FormattedID) must be specified')
10371042
fmtIdQuery = 'FormattedID = "%s"' % formattedID
10381043
response = self.get(entityName, fetch="ObjectID", query=fmtIdQuery,
10391044
workspace=workspace, project=project)
@@ -1044,7 +1049,6 @@ def post(self, entityName, itemData, workspace='current', project='current', **k
10441049
oid = target.ObjectID
10451050
itemData['ObjectID'] = oid
10461051

1047-
10481052
resource = '%s/%s?key=%s' % (entityName.lower(), oid, auth_token)
10491053
context, augments = self.contextHelper.identifyContext(workspace=workspace, project=project)
10501054
if augments:
@@ -1171,7 +1175,7 @@ def getCollection(self, collection_url, **kwargs):
11711175
def addCollectionItems(self, target, items):
11721176
"""
11731177
Given a target which is a hydrated RallyEntity instance having a valid _type
1174-
and a items which is a list of hydrated Rally Entity instances
1178+
and a a list of hydrated Rally Entity instances (items)
11751179
all of the same _type, construct a valid AC WSAPI collection url and
11761180
issue a POST request to that URL supplying the item refs in an appropriate
11771181
JSON structure as the payload.
@@ -1458,6 +1462,7 @@ def getState(self, entity, state_name):
14581462
state = self.get('State', fetch=True, query=criteria, project=None, instance=True)
14591463
return state
14601464

1465+
14611466
def getStates(self, entity):
14621467
"""
14631468
This method must deal with essentially duplicated results as for whatever reason
@@ -1744,7 +1749,6 @@ def _realizeArtifact(self, artifact):
17441749
return art_type, artifact
17451750

17461751

1747-
17481752
def rankAbove(self, reference_artifact, target_artifact):
17491753
"""
17501754
Given a reference_artifact and a target_artifact, make a Rally WSAPI PUT call
@@ -1788,6 +1792,7 @@ def _rankRelative(self, reference_artifact, target_artifact, direction):
17881792
update_item = {artifact_type:{'_ref':target_artifact.ref}}
17891793
return self._postRankRequest(target_artifact, resource, update_item)
17901794

1795+
17911796
def _rankTo(self, target_artifact, location):
17921797
"""
17931798
Given a reference_artifact, make a Rally WSAPI POST call
@@ -1800,6 +1805,7 @@ def _rankTo(self, target_artifact, location):
18001805
update_item = {artifact_type:{'_ref':target_artifact.ref}}
18011806
return self._postRankRequest(target_artifact, resource, update_item)
18021807

1808+
18031809
def _postRankRequest(self, target_artifact, resource, update_item):
18041810
"""
18051811
Given an AgileCentral target Artifact and a resource URI (sans the self.service_url prefix)
@@ -1822,6 +1828,7 @@ def _postRankRequest(self, target_artifact, resource, update_item):
18221828
raise RallyRESTAPIError(problem % (target_artifact.FormattedID, response.errors[0]))
18231829
return response
18241830

1831+
18251832
def _ensureRankItemSanity(self, target_artifact, reference_artifact=None):
18261833
"""
18271834
Ranking can only be done for an item that is an Artifact subclass.
@@ -1841,4 +1848,4 @@ def _ensureRankItemSanity(self, target_artifact, reference_artifact=None):
18411848

18421849
return target_artifact.__class__.__name__.lower()
18431850

1844-
##################################################################################################
1851+
####################################################################################################

0 commit comments

Comments
 (0)