def test_add_attachment(self):
        client = VstsClient(self.instance, self.personal_access_token)
        attachment = None

        # Upload attachment
        with open('./tests/vsts_settings.txt', 'rb') as f:
            attachment = client.upload_attachment('vsts_settings.txt', f)

        # Find a workitem
        query = "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.Title] = 'Test Story'"
        result = client.query(query, 'Contoso')
        id = result.rows[0]['id']

        # Link the attachment
        workitem = client.add_attachment(
            id, attachment.url, 'Linking an attachment to a workitem test')
        self.assertIsNotNone(workitem)
         JsonPatchOperation('replace', SystemFields.STATE,
                            file_n['fields']['System.State']))
     #Updating the Workitems with all the fields
     client.update_workitem(workitem.id, doc)
     logging.info("<PROJECT> WI ID: " + workitem.id +
                  " updated Successfully!")
 try:
     #Uploading and Linking the Attachments to the Newly created WI IDs
     path = '../WI/Attachments/' + str(i) + '/'
     files = [f for f in os.listdir(path)]
     for f in files:
         with open(os.path.join(path, f), 'rb') as x:
             attachment = client.upload_attachment(f, x)
             print(attachment.url)
         client.add_attachment(
             workitem.id, attachment.url, 'Linking attachment: ' + str(f) +
             ' to work item: ' + str(workitem.id))
         logging.info("Attachment : " + str(f) + " linked to " +
                      workitem.id + " Successfully!")
 except:
     pass
 time.sleep(0.2)
 try:
     #Saving the Comments and <PROJECT> WI IDs to uplaod comments
     for x in range(10):
         c_details = {}
         a_id = file_c['comments'][x]
         c_details['id'] = i
         c_details['WI_id'] = workitem.id
         c_details['text'] = a_id['text']
         c_details['d_name'] = a_id['revisedBy']['displayName']
Ejemplo n.º 3
0
                # Create the feature in Azure DevOps
                feature = vsts_client.create_workitem('Contoso', 'Feature',
                                                      doc)

            # Link the user story with feature (PARENT)
            vsts_client.add_link(workitem.id, feature.id, LinkTypes.PARENT)

        # Migrate attachments
        if len(issue.attachments) > 0:
            for attachment in issue.attachments:
                vsts_attachment = None

                # Download the attachment(s) from Jira
                with open('./tmp/{}'.format(attachment.filename), 'wb') as f:
                    f.write(
                        jira_client.download_attachment(
                            attachment.id, attachment.filename))

                # Upload the attachment(s) to VSTS
                with open('./tmp/{}'.format(attachment.filename), 'rb') as f:
                    vsts_attachment = vsts_client.upload_attachment(
                        attachment.filename, f)

                # Link the attachment(s) to the work item
                vsts_client.add_attachment(
                    workitem.id, vsts_attachment.url,
                    'Migrating attachment {}'.format(attachment.filename))

    # Lets wait 2 seconds to prevent request throttling
    time.sleep(2)