def test_synchronize_similar_tasks(self):
        self.connector.initialize()
        self.connector.sde_connect()
        self.connector.alm_connect()

        tasks = self.connector.sde_get_tasks()
        filtered_tasks = self.connector.filter_tasks(tasks)
        self.assertTrue(len(filtered_tasks) > 0)
        task = filtered_tasks[0]
        test_task = task.copy()

        task_id = test_task['id']
        title = test_task['title']

        # construct a similar task (T21 => T21222222) and add to the ALM
        task['id'] = '%s222222' % test_task['id']
        task['title'] = '%s: Sample Title' % AlmConnector._extract_task_id(task['id'])
        task = self.connector.transform_task(task)

        # re-use an issue if one already exists in the ALM
        alm_task1 = self.connector.alm_get_task(task)
        if not alm_task1:
            ref = self.connector.alm_add_task(task)
            self.assertNotNone(ref, 'Could not add issue to ALM for %s' % task['id'])
            alm_task1 = self.connector.alm_get_task(task)
        self.assertNotNone(alm_task1, 'Missing ALM task for %s' % task['id'])

        # Try to sync a similar task
        test_task['id'] = task_id
        test_task['title'] = title
        test_task = self.connector.transform_task(test_task)
        alm_task2 = self.connector.alm_get_task(test_task)
        if not alm_task2:
            ref = self.connector.alm_add_task(test_task)
            self.assertNotNone(ref, 'Could not add issue to ALM for %s' % test_task['id'])
            alm_task2 = self.connector.alm_get_task(test_task)
        self.assertNotNone(alm_task2, 'Missing ALM task for %s' % test_task['id'])

        self.assertNotEqual(alm_task1.get_alm_id(), alm_task2.get_alm_id())

        # clean-up issues in the ALM
        if not self.connector.alm_supports_delete() or not self.connector.config['start_fresh']:
            return

        if alm_task1:
            self.connector.alm_remove_task(alm_task1)

        if alm_task2:
            self.connector.alm_remove_task(alm_task2)
Exemplo n.º 2
0
    def handle(self):
        if not self.config['search_string']:
            raise UsageError('Missing value for search_string')
        if not self.config['replace_string']:
            raise UsageError('Missing value for replace_string')

        self.sde_connect()
        tasks = self.sde_plugin.get_task_list()
        for task in tasks:
            task_notes = self.sde_plugin.get_task_notes(AlmConnector._extract_task_id(task['id']))
            if 'ide' in task_notes:
                for note in task_notes['ide']:
                    new_note_text = re.sub(self.config['search_string'], self.config['replace_string'], note['text'])
                    if new_note_text != note['text']:
                        self.sde_plugin.update_task_ide_note(note['id'], new_note_text)
            if 'text' in task_notes:
                for note in task_notes['text']:
                    new_note_text = re.sub(self.config['search_string'], self.config['replace_string'], note['text'])
                    if new_note_text != note['text']:
                        self.sde_plugin.update_task_text_note(note['id'], new_note_text)

        return True