def setUp(self): """ Plugin setup mirrors the setup that occurs during a sync_alm call. Also initializes the mock responses. """ command_list = load_modules() self.config = Config('help', '', command_list, [], self.ret_chn, 'shell') self.init_alm_connector() self.pre_parse_config() self.config.import_custom_options() self.config['alm_reference_context'] = 2 Config.parse_config_file(self.config, self.conf_path) self.post_parse_config() self.init_response_generator() self.mock_sde_response.initialize(self.config) self.mock_alm_response.initialize(self.response_generator) self.connector.initialize() AlmConnector.init_statuses(self.connector)
def test_alm_full_title(self): task = { 'id': '1099-T12', 'title': 'T12: Sample Title' } config = { 'alm_context': 'Coffee', 'sde_application': 'Breakfast', 'sde_project': 'Sandwich', 'alm_title_format': '[$application ${project} $context] $task_id ${title}' } title = '[Breakfast Sandwich Coffee] T12: Sample Title' task_title = AlmConnector.get_alm_task_title(config, task) self.assertEqual(title, task_title, 'Incorrect full alm title: %s' % task_title)
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)
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