class ConnectionTest(unittest.TestCase):
    def setUp(self):
        #self.con = Connection('http://teamsys.intellij.net', 'resttest', 'resttest')
        self.con = Connection("http://localhost:8081", "root", "root")

    def test_getProject(self):
        p = self.con.getProject('SB')
        self.assertEqual(p.id, 'SB')
        self.assertEqual(p.name, 'Sandbox')

    def test_getSubsystems(self):
        subsystems = self.con.getSubsystems('SB')
        default = [s for s in subsystems if s.isDefault][0]
        self.assertTrue(default is not None)

    def test_getIssue(self):
        i = self.con.getIssue('SB-1')
        self.assertEqual(i.id, 'SB-1')
        self.assertEqual(i.numberInProject, '1')
        self.assertEqual(i.projectShortName, 'SB')

    def test_createIssue(self):
        i = self.con.createIssue('SB', 'resttest', 'Test issue',
                                 'Test description', '2', 'Bug', 'First',
                                 'Open', '', '', '')
        self.assertEqual(i.projectShortName, 'SB')
        self.assertEqual(i.priority, '2')
        self.assertEqual(i.type, 'Bug')
        self.assertEqual(i.subsystem, 'First')

    def test_createIssueAttachment(self):
        i = self.con.createIssue('SB', 'resttest', 'For attachmkents test',
                                 'Test description', '2', 'Bug', 'First',
                                 'Open', '', '', '')
        fname = 'connection_test.py'
        content = open(fname)
        self.con.createAttachment(i.id, fname, content)
        self.assertEqual(fname, self.con.getAttachments(i.id)[0].name)

    def test_createAndDeleteSubsystem(self):
        name = 'Test Subsystem [' + str(random.random()) + "]"
        self.con.createSubsystemDetailed('SB', name, False, 'resttest')
        s = self.con.getSubsystem('SB', name)
        self.assertEqual(s.name, name)
        self.assertEqual(s.isDefault, 'false')
        #todo: uncomment when fix deployed to teamsys
        #self.assertEqual(s.defaultAssignee, 'resttest')
        self.con.deleteSubsystem('SB', name)

    def test_importIssues(self):
        issues = self.con.getIssues("A", "", 0, 10)
        for issue in issues:
            if hasattr(issue, "Assignee"):
                issue["assigneeName"] = issue["Assignee"]
                del issue.Assignee
        self.con.importIssues("B", "assignees", issues)
class ConnectionTest(unittest.TestCase):

    def setUp(self):
        #self.con = Connection('http://teamsys.intellij.net', 'resttest', 'resttest')
        self.con = Connection("http://localhost:8081", "root", "root")
    def test_getProject(self):
        p = self.con.getProject('SB')
        self.assertEqual(p.id, 'SB')
        self.assertEqual(p.name, 'Sandbox')

    def test_getSubsystems(self):
        subsystems = self.con.getSubsystems('SB')
        default = [s for s in subsystems if s.isDefault][0]
        self.assertTrue(default is not None)        

    def test_getIssue(self):
        i = self.con.getIssue('SB-1')
        self.assertEqual(i.id, 'SB-1')
        self.assertEqual(i.numberInProject, '1')
        self.assertEqual(i.projectShortName, 'SB')

    def test_createIssue(self):
        i = self.con.createIssue('SB', 'resttest', 'Test issue', 'Test description', '2', 'Bug', 'First', 'Open', '', '', '')
        self.assertEqual(i.projectShortName, 'SB')
        self.assertEqual(i.priority, '2')
        self.assertEqual(i.type, 'Bug')
        self.assertEqual(i.subsystem, 'First')

    def test_createIssueAttachment(self):
        i = self.con.createIssue('SB', 'resttest', 'For attachmkents test', 'Test description', '2', 'Bug', 'First', 'Open', '', '', '')
        fname = 'connection_test.py'
        content = open(fname)
        self.con.createAttachment(i.id, fname, content)
        self.assertEqual(fname, self.con.getAttachments(i.id)[0].name)

    def test_createAndDeleteSubsystem(self):
        name = 'Test Subsystem [' + str(random.random()) + "]"
        self.con.createSubsystemDetailed('SB', name, False, 'resttest')
        s = self.con.getSubsystem('SB', name)
        self.assertEqual(s.name, name)
        self.assertEqual(s.isDefault, 'false')
        #todo: uncomment when fix deployed to teamsys
        #self.assertEqual(s.defaultAssignee, 'resttest')
        self.con.deleteSubsystem('SB', name)

    def test_importIssues(self):
        issues = self.con.getIssues("A", "", 0, 10)
        for issue in issues:
            if hasattr(issue, "Assignee"):
                issue["assigneeName"] = issue["Assignee"]
                del issue.Assignee
        self.con.importIssues("B", "assignees", issues)
def do_move(source_url, source_login, source_password,
            target_url, target_login, target_password, source_issue_id, target):
    print("source_url       : " + source_url)
    print("source_login     : "******"source_password  : "******"target_url       : " + target_url)
    print("target_login     : "******"target_password  : "******"source_id        : " + source_issue_id)

    if target.find('-') > -1:
        print("target_id        : " + target)
        target_project_id, target_issue_number = target.split('-')
    else:
        print("target_project_id: " + target)
        target_project_id = target
        target_issue_number = None

    # connecting
    try:
        target = Connection(target_url, target_login, target_password)
        print("Connected to target url [%s]" % target_url)
    except Exception as ex:
        print("Failed to connect to target url [%s] with login/password [%s/%s]"
              % (target_url, target_login, target_password))
        raise ex

    try:
        source = Connection(source_url, source_login, source_password)
        print("Connected to source url [%s]" % source_url)
    except Exception as ex:
        print("Failed to connect to source url [%s] with login/password [%s/%s]"
              % (source_url, source_login, source_password))
        raise ex

    try:
        target.getProject(target_project_id)
    except Exception as ex:
        print("Can't connect to target project [%s]" % target_project_id)
        raise ex

    # twin issues
    try:
        source_issue = source.getIssue(source_issue_id)
    except Exception as ex:
        print("Failed to get issue [%s]" % source_issue_id)
        raise ex

    target_issue = Issue()

    # import users if needed
    name_fields = ["reporterName", "assigneeName", "updaterName"]
    for field in name_fields:
        if field in source_issue:
            check_user(source_issue[field], source, target)

    if not target_issue_number:
        target_issue_number = str(get_new_issue_id(target_project_id, target))
    target_issue.numberInProject = target_issue_number

    # check subsystem
    target_subsystem = None
    try:
        target.getSubsystem(target_project_id, source_issue.subsystem)
        target_subsystem = source_issue.subsystem
    except (YouTrackException, AttributeError):
        pass
    target_issue.subsystem = target_subsystem
    for field in PREDEFINED_FIELDS:
        if field in source_issue:
            target_issue[field] = source_issue[field]

    if "Type" in source_issue:
        target_issue.type = source_issue["Type"]
    elif "type" in source_issue:
        target_issue.type = source_issue["type"]
    else:
        target_issue.type = "Bug"

    # convert custom field
    target_cfs = target.getProjectCustomFields(target_project_id)
    for cf in target_cfs:
        cf_name = cf.name
        if cf_name in source_issue:
            target_issue[cf_name] = source_issue[cf_name]

    # comments
    target_issue.comments = source_issue.getComments()
    for comment in target_issue.comments:
        check_user(comment.author, source, target)

    # import issue
    print(target.importIssues(
        target_project_id,
        "",
        [target_issue]))

    # attachments
    for attachment in source_issue.getAttachments():
        check_user(attachment.authorLogin, source, target)
        attachment.url = attachment.url.replace(source_url, "")
        target.createAttachmentFromAttachment(
            "%s-%s" % (target_project_id, target_issue.numberInProject),
            attachment)

    # work items
    if get_time_tracking_state(
            source, target, source_issue_id.split('-')[0],
            target_project_id):
        workitems = source.getWorkItems(source_issue_id)
        if workitems:
            existing_workitems = dict()
            target_workitems = target.getWorkItems(
                target_project_id + '-' + target_issue_number)
            if target_workitems:
                for w in target_workitems:
                    _id = '%s\n%s\n%s' % (w.date, w.authorLogin, w.duration)
                    if hasattr(w, 'description'):
                        _id += '\n%s' % w.description
                    existing_workitems[_id] = w
            new_workitems = []
            for w in workitems:
                _id = '%s\n%s\n%s' % (w.date, w.authorLogin, w.duration)
                if hasattr(w, 'description'):
                    _id += '\n%s' % w.description
                if _id not in existing_workitems:
                    new_workitems.append(w)
            if new_workitems:
                print("Process workitems for issue [ " + source_issue_id + "]")
                try:
                    for w in new_workitems:
                        check_user(w.authorLogin, source, target)
                    target.importWorkItems(
                        target_project_id + '-' + target_issue_number,
                        new_workitems)
                except YouTrackException as e:
                    print("Failed to import workitems: " + str(e))

    # links
    link_importer = LinkImporter(target)
    links2import = source_issue.getLinks()
    link_importer.collectLinks(links2import)
    link_importer.addAvailableIssue(source_issue)
    for l in links2import:
        link_importer.addAvailableIssue(source.getIssue(l.source))
        link_importer.addAvailableIssue(source.getIssue(l.target))
    link_importer.importCollectedLinks()
Exemplo n.º 4
0
def do_move(source_url, source_login, source_password,
            target_url, target_login, target_password, source_issue_id, target):
    print("source_url       : " + source_url)
    print("source_login     : "******"source_password  : "******"target_url       : " + target_url)
    print("target_login     : "******"target_password  : "******"source_id        : " + source_issue_id)

    if target.find('-') > -1:
        print("target_id        : " + target)
        target_project_id, target_issue_number = target.split('-')
    else:
        print("target_project_id: " + target)
        target_project_id = target
        target_issue_number = None

    # connecting
    try:
        target = Connection(target_url, target_login, target_password)
        print("Connected to target url [%s]" % target_url)
    except Exception as ex:
        print("Failed to connect to target url [%s] with login/password [%s/%s]"
              % (target_url, target_login, target_password))
        raise ex

    try:
        source = Connection(source_url, source_login, source_password)
        print("Connected to source url [%s]" % source_url)
    except Exception as ex:
        print("Failed to connect to source url [%s] with login/password [%s/%s]"
              % (source_url, source_login, source_password))
        raise ex

    try:
        target.getProject(target_project_id)
    except Exception as ex:
        print("Can't connect to target project [%s]" % target_project_id)
        raise ex

    # twin issues
    try:
        source_issue = source.getIssue(source_issue_id)
    except Exception as ex:
        print("Failed to get issue [%s]" % source_issue_id)
        raise ex

    target_issue = Issue()

    # import users if needed
    name_fields = ["reporterName", "assigneeName", "updaterName"]
    for field in name_fields:
        if field in source_issue:
            check_user(source_issue[field], source, target)

    if not target_issue_number:
        target_issue_number = str(get_new_issue_id(target_project_id, target))
    target_issue.numberInProject = target_issue_number

    # check subsystem
    target_subsystem = None
    try:
        target.getSubsystem(target_project_id, source_issue.subsystem)
        target_subsystem = source_issue.subsystem
    except (YouTrackException, AttributeError):
        pass
    target_issue.subsystem = target_subsystem
    for field in PREDEFINED_FIELDS:
        if field in source_issue:
            target_issue[field] = source_issue[field]

    if "Type" in source_issue:
        target_issue.type = source_issue["Type"]
    elif "type" in source_issue:
        target_issue.type = source_issue["type"]
    else:
        target_issue.type = "Bug"

    # convert custom field
    target_cfs = target.getProjectCustomFields(target_project_id)
    for cf in target_cfs:
        cf_name = cf.name
        if cf_name in source_issue:
            target_issue[cf_name] = source_issue[cf_name]

    # comments
    target_issue.comments = source_issue.getComments()
    for comment in target_issue.comments:
        check_user(comment.author, source, target)

    # attachments
    print(target.importIssues(
        target_project_id,
        target.getProjectAssigneeGroups(target_project_id)[0].name,
        [target_issue]))
    for attachment in source_issue.getAttachments():
        check_user(attachment.authorLogin, source, target)
        target.createAttachmentFromAttachment(
            "%s-%s" % (target_project_id, target_issue.numberInProject),
            attachment)