def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if len(args) != 2: errout( 'ERROR: You must supply an Artifact identifier and an attachment file name' ) errout(USAGE) sys.exit(1) target, attachment_file_name = args server, username, password, apikey, workspace, project = rallyWorkset( options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging( 'rally.hist.creattach') # name of file you want logging to go to artifact = validateTarget(rally, target) me = rally.getUserInfo(username=username).pop(0) #print "%s user oid: %s" % (username, me.oid) att = rally.addAttachment(artifact, attachment_file_name) print("created Attachment: %s for %s" % (attachment_file_name, target))
def test_add_tcr_attachment(): """ Add an Attachment to a TestCaseResult item Create a TestCase, save a reference Create a TestCaseResult to be associated with the TestCase Create an attachment Attach the Attachment to the TestCaseResult item """ rally = Rally(server=TRIAL, user=TRIAL_USER, password=TRIAL_PSWD) wksp = rally.getWorkspace() assert wksp.Name == DEFAULT_WORKSPACE response = rally.get('Project', fetch=False, limit=10) assert response != None assert response.status_code == 200 proj = rally.getProject() # proj.Name == Sample Project assert proj.Name == 'Sample Project' tc_info = { "Workspace" : wksp.ref, "Project" : proj.ref, "Name" : "Heat exposure", "Type" : "Functional", } test_case = rally.create('TestCase', tc_info) assert int(test_case.oid) > 0 tcr_info = { "Workspace" : wksp.ref, "TestCase" : test_case.ref, "Date" : "2016-05-17T14:30:28.000Z", "Build" : 17, "Verdict" : "Pass" } tcr = rally.create('TestCaseResult', tcr_info) assert int(tcr.oid) > 0 attachment_name = "Addendum.txt" att_ok = conjureUpAttachmentFile(attachment_name) assert att_ok == True att = rally.addAttachment(tcr, attachment_name) assert att.Name == attachment_name
def test_add_attachment(): """ """ rally = Rally(server=TRIAL, user=TRIAL_USER, password=TRIAL_PSWD) # find a Project with some US artifacts # pick one with no attachments # create an attachment file (or choose a smallish file with a commonly used suffix) # create the attachment in Rally and link it to the US artifact wksp = rally.getWorkspace() assert wksp.Name == DEFAULT_WORKSPACE response = rally.get('Project', fetch=False, limit=10) assert response != None assert response.status_code == 200 proj = rally.getProject() # proj.Name == DEFAULT_PROJECT assert proj.Name == DEFAULT_PROJECT #response = rally.get("UserStory", fetch="FormattedID,Name,Attachments") #for story in response: # print "%s %-48.48s %d" % (story.FormattedID, story.Name, len(story.Attachments)) candidate_story = "US1" # was "US96" in trial response = rally.get("UserStory", fetch="FormattedID,Name,Attachments", query='FormattedID = "%s"' % candidate_story) ##print(response.resultCount) story = response.next() assert len(story.Attachments) == 0 attachment_name = "Addendum.txt" att_ok = conjureUpAttachmentFile(attachment_name) assert att_ok == True att = rally.addAttachment(story, attachment_name) assert att.Name == attachment_name response = rally.get("UserStory", fetch="FormattedID,Name,Attachments", query='FormattedID = "%s"' % candidate_story) story = response.next() assert len(story.Attachments) == 1
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] server, user, password, workspace, project = rallySettings(options) print " ".join(["|%s|" % item for item in [server, user, '********', workspace, project]]) rally = Rally(server, user, password, workspace=workspace, version="1.30") # specify the Rally server and credentials rally.enableLogging('rally.hist.creattach') # name of file you want logging to go to if len(args) != 2: errout('ERROR: You must supply an Artifact identifier and an attachment file name') errout(USAGE) sys.exit(1) target, attachment_file_name = args artifact = validateTarget(rally, target) me = rally.getUserInfo(username=user).pop(0) #print "%s user oid: %s" % (user, me.oid) att = rally.addAttachment(artifact, attachment_file_name) print "created Attachment: %s for %s" % (attachment_file_name, target)
def main(args): options = [opt for opt in args if opt.startswith('--')] args = [arg for arg in args if arg not in options] if len(args) != 2: errout('ERROR: You must supply an Artifact identifier and an attachment file name') errout(USAGE) sys.exit(1) target, attachment_file_name = args server, username, password, apikey, workspace, project = rallyWorkset(options) if apikey: rally = Rally(server, apikey=apikey, workspace=workspace, project=project) else: rally = Rally(server, user=username, password=password, workspace=workspace, project=project) rally.enableLogging('rally.hist.creattach') # name of file you want logging to go to artifact = validateTarget(rally, target) me = rally.getUserInfo(username=user).pop(0) #print "%s user oid: %s" % (user, me.oid) att = rally.addAttachment(artifact, attachment_file_name) print "created Attachment: %s for %s" % (attachment_file_name, target)
def test_add_attachment(): """ """ # find a Project with some US artifacts, pick one with no attachments target_workspace = 'Yeti Rally Workspace' target_project = 'Anti-Cyclone' target_story = 'US6099' target_attachment_file = 'test/alpine-snow-glen-plake-quote.png' attachment_name = os.path.basename(target_attachment_file) attachment_type = 'image/png' rally = Rally(server=RALLY, user=YETI_USER, password=YETI_PSWD, workspace=target_workspace, project=target_project) # create an attachment file (or choose a smallish file with a commonly used suffix) # create the attachment in Rally and link it to the US artifact wksp = rally.getWorkspace() assert wksp.Name == target_workspace response = rally.get('Project', fetch=False, limit=10) assert response != None assert response.status_code == 200 proj = rally.getProject() # proj.Name == target_project assert proj.Name == target_project #response = rally.get("UserStory", fetch="FormattedID,Name,Attachments") #for story in response: # print "%s %-48.48s %d" % (story.FormattedID, story.Name, len(story.Attachments)) criteria = f'FormattedID = "{target_story}"' response = rally.get("UserStory", fetch="FormattedID,Name,Attachments", query=criteria) ##print(response.resultCount) story = response.next() if len(story.Attachments): for att in story.Attachments: rally.deleteAttachment(story, att.Name) response = rally.get("UserStory", fetch="FormattedID,Name,Attachments", query='FormattedID = "%s"' % target_story) story = response.next() ##print(response.resultCount) assert len(story.Attachments) == 0 #attachment_name = "Addendum.txt" # #att_ok = conjureUpAttachmentFile(attachment_name) #assert att_ok == True #att = rally.addAttachment(story, attachment_name) att = rally.addAttachment(story, target_attachment_file, mime_type=attachment_type) assert att.Name == attachment_name criteria = f'FormattedID = "{target_story}"' response = rally.get("UserStory", fetch="FormattedID,Name,Attachments", query=criteria) story = response.next() assert len(story.Attachments) == 1 attachment = story.Attachments[0] assert attachment.Name == attachment_name
def test_add_tcr_attachment(): """ Add an Attachment to a TestCaseResult item Create a TestCase, save a reference Create a TestCaseResult to be associated with the TestCase Create an attachment Attach the Attachment to the TestCaseResult item """ #rally = Rally(server=RALLY, user=RALLY_USER, password=RALLY_PSWD) rally = Rally(server=RALLY, user=RALLY_USER, apikey=APIKEY, workspace=DEFAULT_WORKSPACE, project=DEFAULT_PROJECT) wksp = rally.getWorkspace() assert wksp.Name == DEFAULT_WORKSPACE response = rally.get('Project', fetch=False, limit=10) assert response != None assert response.status_code == 200 proj = rally.getProject() # proj.Name == Sample Project assert proj.Name == 'Sample Project' tc_info = { "Workspace": wksp.ref, "Project": proj.ref, "Name": "Heat exposure", "Type": "Functional", } test_case = rally.create('TestCase', tc_info) assert int(test_case.oid) > 0 current = timestamp()[:-4].replace(' ', 'T') + "Z" tcr_info = { "Workspace": wksp.ref, "TestCase": test_case.ref, "Date": current, "Build": 27, "Verdict": "Pass" } tcr = rally.create('TestCaseResult', tcr_info) assert int(tcr.oid) > 0 attachment_name = "Addendum.txt" att_ok = conjureUpAttachmentFile(attachment_name) assert att_ok == True att = rally.addAttachment(tcr, attachment_name) assert att.Name == attachment_name target = ['Build = 27', f'TestCase = {test_case.ref}'] response = rally.get("TestCaseResult", fetch='ObjectID,FormattedID,Attachments', query=target, project=None) assert response.resultCount == 1 tcr = response.next() attachment = rally.getAttachment(tcr, attachment_name) assert attachment.Name == attachment_name att_type = attachment.ContentType assert att_type == 'text/plain' att = tcr.Attachments[0] actual_attachment_content = attachment.Content.decode('UTF-8').replace( "\r", '') att_content = att.Content.decode('UTF-8').replace("\r", '') assert actual_attachment_content == EXAMPLE_ATTACHMENT_CONTENT assert att_content == EXAMPLE_ATTACHMENT_CONTENT #assert attachment.Content.decode('UTF-8') == EXAMPLE_ATTACHMENT_CONTENT #assert att.Content.decode('UTF-8') == EXAMPLE_ATTACHMENT_CONTENT rally.deleteAttachment(tcr, attachment_name) rally.delete('TestCaseResult', tcr) rally.delete('TestCase', test_case)