示例#1
0
    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)
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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))
示例#5
0
    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))
示例#6
0
 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'
示例#7
0
    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))
示例#8
0
 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'
示例#9
0
    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])
示例#10
0
    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)
示例#11
0
    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)
示例#12
0
    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)
示例#13
0
    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)
示例#14
0
    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))
示例#15
0
    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()
示例#16
0
    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))
示例#17
0
    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)
示例#18
0
 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)