Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

booster-api: Use str.format() function for string concatenation #764

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions booster_api/features/src/poc2.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def runTest(self, theString):
projectName = os.environ.get('PROJECT_NAME')
pipeline = os.environ.get('PIPELINE')
spaceId = helpers.getSpaceID()
authHeader = 'Bearer ' + theToken
authHeader = 'Bearer {}'.format(theToken)

print 'starting test.....'

Expand All @@ -37,7 +37,7 @@ def runTest(self, theString):

print 'making request ...'
r = requests.post('https://forge.api.openshift.io/api/osio/import', headers=headers, data=data)
print 'request results = ' + r.text
print 'request results = {}'.format(r.text)

result = r.text
if re.search('uuid' , result):
Expand Down
24 changes: 14 additions & 10 deletions booster_api/features/src/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,32 @@ def createSpace(self, spaceName):

serverAddress = os.getenv("SERVER_ADDRESS")

authHeader = 'Bearer ' + theToken
authHeader = 'Bearer {}'.format(theToken)

headers = {'Accept': 'application/json',
'Authorization': authHeader,
'X-App': 'osio',
'X-Git-Provider': 'GitHub',
'Content-Type': 'application/json'}

data = '{\
"data": {\
"attributes": {\
data = '{{\
"data": {{\
"attributes": {{\
"description": "This is the osioperf collaboration space",\
"name": "' + spaceName + '"\
},\
"name": "{}"\
}},\
"type": "spaces"\
}\
}'
}}\
}}'.format(spaceName)


print 'making request ...'
r = requests.post(serverAddress + '/api/spaces', headers=headers, data=data)
print 'request results = ' + r.content
r = requests.post(
'{}/api/spaces'.format(serverAddress),
headers=headers,
data=data
)
print 'request results = {}'.format(r.content)

try:
respJson = r.json()
Expand Down
25 changes: 15 additions & 10 deletions booster_api/features/src/support/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ def get_user_tokens(index=0):
def create_space_name(template="BDD"):
var = datetime.datetime.now()
var = var.isoformat().rsplit('.')[0]
space = os.getenv("OSIO_USERNAME") + "-" + template + "-space-" + var
space = "{}-{}-space-{}".format(
os.getenv("OSIO_USERNAME"),
template,
var
)

space = space.replace('@','-')
space = space.replace(':','-')
space = space.replace('.','-')
print 'The spacename is: ' + space
print "The spacename is: {}".format(space)
return space

def getSpaceID():
Expand Down Expand Up @@ -145,7 +150,7 @@ def generate_entity_names(static_string=None, no_of_names=1, reverse=False, rese
total_entities = count + no_of_names
for i in xrange(count, total_entities):
if static_string is not None:
mylist.append(static_string + "_" + str(i))
mylist.append("{}_{}".format(static_string,str(i)))
else:
mylist.append(i)
#Updating global counter
Expand All @@ -161,7 +166,7 @@ def create_workitem_SDD(title=None, spaceid=None, witype=None, iterationid=None)
return None
## Create workitems in Iterations context
elif iterationid is not None:
api = "api/spaces/" + spaceid + "/workitems"
api = "api/spaces/{}/workitems".format(spaceid)
url = constants.launch_detail.create_url(api)
f = read_post_data_file('create_wi_in_iter.json', replace={'$wi_nos_generated':title, '$witype': witype, '$iteration_id': iterationid})
r = req.post(url, headers=constants.request_detail.headers_default, json=f)
Expand All @@ -170,7 +175,7 @@ def create_workitem_SDD(title=None, spaceid=None, witype=None, iterationid=None)
return r
## Create workitems in backlog view
else:
api = "api/spaces/" + spaceid + "/workitems"
api = "api/spaces/{}/workitems".format(spaceid)
url = constants.launch_detail.create_url(api)
f = read_post_data_file('create_wi_in_backlog.json', replace={'$wi_nos_generated':title, '$witype': witype})
r = req.post(url, headers=constants.request_detail.headers_default, json=f)
Expand All @@ -184,7 +189,7 @@ def create_workitem_SCRUM(title=None, spaceid=None, witype=None, iterationid=Non
return None
## Create workitems in Iterations context
elif iterationid is not None:
api = "api/spaces/" + spaceid + "/workitems"
api = "api/spaces/{}/workitems".format(spaceid)
url = constants.launch_detail.create_url(api)
if witype == constants.workitem_constants.witypetask1:
f = read_post_data_file('create_wi_in_iter_scrum.json', replace={'$wi_nos_generated':title, '$witype': witype, '$state': 'To Do', '$iteration_id': iterationid})
Expand All @@ -196,7 +201,7 @@ def create_workitem_SCRUM(title=None, spaceid=None, witype=None, iterationid=Non
return r
## Create workitems in backlog view
else:
api = "api/spaces/" + spaceid + "/workitems"
api = "api/spaces/{}/workitems".format(spaceid)
url = constants.launch_detail.create_url(api)
if witype == constants.workitem_constants.witypetask1:
f = read_post_data_file('create_wi_in_backlog_scrum.json', replace={'$wi_nos_generated':title, '$witype': witype, '$state': 'To Do'})
Expand All @@ -213,7 +218,7 @@ def add_workitem_comment(workitem_link=None, comment_text=None):
return None
else:
## Add a comment to the workitem
wi_comment_api = workitem_link + "/comments"
wi_comment_api = "{}/comments".format(workitem_link)
f = read_post_data_file('add_wi_comment.json', replace={'$comment_text':comment_text})
return req.post(wi_comment_api, headers=constants.request_detail.headers_default, json=f)

Expand All @@ -223,7 +228,7 @@ def create_new_label(label_text=None):
return None
else:
## Add a Label to the space
create_label_api = "api/spaces/" + constants.dynamic_vars.spaceid + "/labels"
create_label_api = "api/spaces/{}/labels".format(constants.dynamic_vars.spaceid)
url = constants.launch_detail.create_url(create_label_api)
f = read_post_data_file('create_label.json', replace={'$label_name':label_text})
return req.post(url, headers=constants.request_detail.headers_default, json=f)
Expand Down Expand Up @@ -270,7 +275,7 @@ def delete_space(spaceid=None):
return None
else:
## Delete a space
api = "api/spaces/" + spaceid
api = "api/spaces/{}".format(spaceid)
url = constants.launch_detail.create_url(api)
r = req.delete(url, headers=constants.request_detail.headers_default)
return r
Loading