def test_init_using_list_of_queries_and_strings_continues_if_query_is_delayed( self, mock_list, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_list_of_queries_and_strings_continues( ) list_contents = [ "This is a string entry", Filter('project=msportal', max_results=5, fields=['id', 'description', 'priority']) ] effect = [item for item in result_list if isinstance(item, ResultList)] effect[1] = InvalidQueryError('The query you have provided is invalid') mock_manager.side_effect = effect Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) with patch('pyccata.core.filter.Filter.complete', new_callable=PropertyMock) as mock_thread_complete: mock_thread_complete.side_effect = [False, False, True] unordered = List(self._thread_manager, config) unordered.run() self.assertTrue(unordered._complete)
def test_init_using_single_query_creates_list_of_items( self, mock_list, mock_results): results = ["test 1", "test 2", "test 3", "test 4", "test 5"] resultset = Issue() resultset.pipelines = results list_contents = Filter('project=msportal', max_results=5, fields=['id', 'description', 'priority']) Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='pipelines', prepend=None) calls = [call(item, style='ListBullet') for item in results] with patch('pyccata.core.filter.Filter.complete', new_callable=PropertyMock): unordered = List(self._thread_manager, config) mock_results.return_value = [resultset] list_contents.complete.return_value = True unordered.run() unordered.render(self._report_manager) mock_list.assert_has_calls(calls)
def test_init_using_single_query_creates_list(self, mock_list, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_single_query_in_config() list_contents = Filter('project=msportal', max_results=5, fields=['id', 'description', 'priority']) mock_manager.return_value = result_list Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) calls = [ call(item.description, style='ListBullet') for item in result_list ] unordered = List(self._thread_manager, config) self._thread_manager.execute() unordered.render(self._report_manager) mock_list.assert_has_calls(calls)
def test_get_len_returns_length_of_self_if_content_is_list(self): list_contents = ['test 1', 'test 2', 'test 3'] Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) self.assertEqual(3, len(unordered))
def test_list_contains_item_if_content_is_list(self): list_contents = ['test 1', 'test 2', 'test 3'] Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) self.assertTrue(('test 1' in unordered))
def test_set_item_raises_error_if_content_is_list_and_results_is_none( self): list_contents = [] Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) with self.assertRaises(IndexError): unordered[0] = 'hello world'
def test_delete_item_if_content_is_list(self): list_contents = ['test 1', 'test 2', 'test 3'] Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) del unordered[2] self.assertEquals(2, len(unordered))
def test_set_item_raises_error_if_content_is_filter_and_filter_results_is_none( self): list_contents = Filter('project=mssportal', max_results=5, fields=['id', 'description', 'priority']) Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) with self.assertRaises(IndexError): unordered[0] = 'hello world'
def test_reverse_list_if_content_is_list(self): list_contents = ['test 1', 'test 2', 'test 3'] Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) unordered = list(reversed(unordered)) self.assertEquals('test 3', unordered[0]) self.assertEquals('test 2', unordered[1]) self.assertEquals('test 1', unordered[2])
def test_init_creates_list(self, mock_list): list_contents = ['test item 1', 'test item 2', 'test item 3'] Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='', prepend=None) calls = [call(item, style='ListBullet') for item in list_contents] unordered = List(self._thread_manager, config) unordered.run() unordered.render(self._report_manager) mock_list.assert_has_calls(calls)
def test_list_fails_if_content_is_invalid_tuple(self, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_single_query_in_config() Filter = namedtuple('Filter', 'bob fields') list_contents = Filter('project=msportal', fields=['id', 'description', 'priority']) mock_manager.return_value = result_list Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) with self.assertRaises(ArgumentValidationError): unordered = List(self._thread_manager, config)
def test_run_completes_if_filter_delays_in_completing(self): ListContents = namedtuple('ListContents', 'query fields') list_contents = ListContents('project=msportal', fields=['id', 'description', 'priority']) Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) with patch('pyccata.core.filter.Filter.complete', new_callable=PropertyMock) as mock_thread_complete: unordered = List(self._thread_manager, config) mock_thread_complete.side_effect = [False, False, True] unordered.run() self.assertTrue(unordered._complete)
def test_run_completes_if_thread_fails(self): ListContents = namedtuple('ListContents', 'query fields') list_contents = ListContents('project=msportal', fields=['id', 'description', 'priority']) Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) with patch('pyccata.core.threading.Threadable.complete', new_callable=PropertyMock) as mock_thread_complete: unordered = List(self._thread_manager, config) mock_thread_complete.return_value = True unordered._content._failure = InvalidQueryError( 'Your JQL contains an error before Pipeline') unordered.run() self.assertTrue(unordered._complete)
def test_list_contains_item_if_content_is_tuple(self, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_single_query_in_config() ListContents = namedtuple('ListContents', 'query fields') list_contents = ListContents('project=msportal', fields=['id', 'description', 'priority']) mock_manager.return_value = result_list Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) self._thread_manager.execute() self.assertTrue((result_list[3] in unordered))
def test_list_completes_if_content_filter_fails(self, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_single_query_in_config() list_contents = Filter('project=msportal', max_results=5, fields=['id', 'description', 'priority']) mock_manager.return_value = result_list Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) with patch('pyccata.core.filter.Filter.failure', new_callable=PropertyMock) as mock_failure: mock_failure.return_value = RuntimeError('I blew up') self._thread_manager.execute()
def test_delete_item_if_content_is_filter(self, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_single_query_in_config() list_contents = Filter('project=msportal', max_results=5, fields=['id', 'description', 'priority']) mock_manager.return_value = result_list Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) unordered = List(self._thread_manager, config) self._thread_manager.execute() del unordered[1] self.assertEquals(4, len(unordered))
def test_init_using_list_of_queries_and_strings_continues_if_query_errors( self, mock_list, mock_manager): result_list = DataProviders( ).get_results_for_list_init_with_list_of_queries_and_strings_continues( ) list_contents = [ Filter('project=msportal', max_results=5, fields=['id', 'description', 'priority']), "This is a string entry", Filter('project=svdesk', max_results=5, fields=['id', 'description', 'priority']), Filter('project=mvp', max_results=5, fields=['id', 'description', 'priority']), "This is another string entry" ] effect = [item for item in result_list if isinstance(item, ResultList)] effect[1] = InvalidQueryError('The query you have provided is invalid') mock_manager.side_effect = effect Config = namedtuple('Config', 'content style field prepend') config = Config(content=list_contents, style='unordered', field='description', prepend=None) calls = [ call(item[0].description if isinstance(item, list) else item, style='ListBullet') for item in result_list ] del calls[2] unordered = List(self._thread_manager, config) self._thread_manager.execute() unordered.render(self._report_manager) mock_list.assert_has_calls(calls)
def test_setup_raises_argument_validation_error_if_style_is_invalid(self): Config = namedtuple('Config', 'content style field prepend') config = Config(content=[], style='IAmInvalid', field='', prepend=None) with self.assertRaises(ArgumentValidationError): unordered = List(self._thread_manager, config)