示例#1
0
    def test_run_notifies_observers(self, mock_load, mock_jira_client):
        mock_jira_client.return_value = None
        with patch('pyccata.core.configuration.Configuration.manager',
                   new_callable=PropertyMock) as mock_manager:
            with patch(
                    'pyccata.core.configuration.Configuration._configuration',
                    new_callable=PropertyMock) as mock_config:
                mock_config.return_value = DataProviders._get_config_for_test()
                mock_manager.return_value = 'jira'
                mock_filter = Filter('assignee = "Bob"',
                                     namespace='pyccata.core')
                mock_filter.projectmanager = ProjectManager()
                mock_filter.projectmanager._client._client = DataProviders._get_client(
                )

                another_filter = Filter('assignee = "Bob"',
                                        namespace='pyccata.core')
                mock_filter.append(another_filter)

                mock_filter.run()
                self.assertEquals(mock_filter.failure, None)
                self.assertTrue(mock_filter.complete)
                self.assertEqual(
                    len(mock_filter.results),
                    len(DataProviders._test_data_for_search_results()))
                self.assertEqual(mock_filter._results, another_filter._results)
示例#2
0
 def test_adding_filter_ignores_argument_validation_error_and_adds_to_self(self, mock_query, mock_load, mock_jira_client):
     mock_query.side_effect = ArgumentValidationError('1st', 'append', 'pyccata.core.filter.Filter', 'object')
     mock_jira_client.return_value = DataProviders._get_client()
     with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager:
         with patch('pyccata.core.configuration.Configuration._configuration', new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = 'jira'
             manager = ThreadManager()
             manager.append(TestObservableThread())
             self.assertEquals(1, len(manager))
示例#3
0
 def test_adding_filter_adds_project_manager(self, mock_load, mock_jira_client):
     mock_jira_client.return_value = DataProviders._get_client()
     with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager:
         with patch('pyccata.core.configuration.Configuration._configuration', new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = 'jira'
             manager = ThreadManager()
             self.assertIsInstance(manager.projectmanager, ProjectManager)
             self.assertIsInstance(manager.querymanager, QueryManager)
             self.assertIsInstance(manager.configuration, Configuration)
             mock_filter = Filter('assignee = "Foo"')
             manager.append(mock_filter)
             self.assertIsInstance(mock_filter.projectmanager, ProjectManager)
示例#4
0
    def test_execute_batches_pool_size_and_fills_on_complete(self, mock_query, mock_load, mock_jira_client):
        mock_query.side_effect = ArgumentValidationError('1st', 'append', 'pyccata.core.filter.Filter', 'object')
        mock_jira_client.return_value = DataProviders._get_client()
        with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager:
            with patch('pyccata.core.configuration.Configuration._configuration', new_callable=PropertyMock) as mock_config:
                mock_config.return_value = DataProviders._get_config_for_test()
                mock_manager.return_value = 'jira'

                manager = ThreadManager()
                # start with 100 threads...
                for i in range(100):
                    manager.append(ViableTestThread())
                manager.start()
示例#5
0
    def test_execute_batches_pool_size_and_logs_on_error(self, mock_query, mock_load, mock_jira_client):
        mock_query.side_effect = ArgumentValidationError('1st', 'append', 'pyccata.core.filter.Filter', 'object')
        mock_jira_client.return_value = DataProviders._get_client()
        with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager:
            with patch('pyccata.core.configuration.Configuration._configuration', new_callable=PropertyMock) as mock_config:
                mock_config.return_value = DataProviders._get_config_for_test()
                mock_manager.return_value = 'jira'

                manager = ThreadManager()
                test_threads = DataProviders.some_threads_explode()
                for thread in test_threads:
                    manager.append(thread)
                manager.start()
示例#6
0
    def test_render_returns_if_section_contains_empty_table(
            self, mock_load, mock_jira_client):
        Rows = namedtuple('Row', 'query fields')

        row_config = Rows(query="project=bob and issuetype=Bug",
                          fields=["key", "description", "priority"])
        #rows = Filter(row_config.query, fields=row_config.fields)
        #self._thread_manager.append(rows)
        columns = ['Name', 'Description']

        TableConfig = namedtuple('TableConfig', 'rows columns style')
        table_config = TableConfig(rows=row_config,
                                   columns=columns,
                                   style='Light heading 1')

        StructureConfig = namedtuple('StructureConfig', 'type title content')
        structure_config = StructureConfig(type='table',
                                           title='Hello world',
                                           content=table_config)

        SectionConfig = namedtuple('SectionConfig',
                                   'title abstract level structure')
        section_config = SectionConfig(
            title='Test',
            abstract='This is a test for empty tables',
            level=1,
            structure=[structure_config])

        mock_jira_client.return_value = None
        with patch('pyccata.core.configuration.Configuration.manager',
                   new_callable=PropertyMock) as mock_manager:
            with patch(
                    'pyccata.core.configuration.Configuration._configuration',
                    new_callable=PropertyMock) as mock_config:
                mock_config.return_value = DataProviders._get_config_for_test()
                mock_manager.return_value = 'jira'
                section = Section(self._thread_manager, section_config)
                rows = section._structure[0].rows
                rows._thread_manager = self._thread_manager
                rows._project_manager = ProjectManager()
                rows.projectmanager._client._client = DataProviders._get_client_without_results(
                )

                document = ReportManager()
                self._thread_manager.execute()
                section.render(document)

                self.assertEquals(0, rows.results.total)
示例#7
0
 def test_manager_returns_list_of_projects(self, mock_load,
                                           mock_jira_client):
     key = 'jira'
     mock_jira_client.return_value = None
     data = DataProviders._test_data_for_search_results()
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = key
             manager = ProjectManager()
             self.assertIsInstance(manager.client.client, JIRA)
             manager._client._client = DataProviders._get_client()
             self.assertEqual(len(manager.projects()), 3)
示例#8
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)
示例#9
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)
示例#10
0
    def test_run_raises_type_error_if_attachments_callback_function_is_not_set(
        self,
        mock_config_list,
        mock_results,
        mock_jira_results,
        mock_jira_client,
        mock_open
    ):
        mock_jira_client.return_value = None
        mock_config_list.return_value = [self._path]
        Configuration.NAMESPACE = 'pyccata.core'
        report = ReportManager()
        report.add_callback('attachments', None)
        mock_jira_results.return_value = DataProviders._test_data_for_attachments()
        server = namedtuple('Server', 'server_address attachments')
        mock_results.return_value = server(server_address=None, attachments=None)

        self.assertIsInstance(Configuration().replacements, Replacements)

        Config = namedtuple('Config', 'query fields collate output_path')
        config = Config(
            query='project=test and attachments is not empty',
            fields=[
                'key',
                'attachments'
            ],
            collate='zip',
            output_path='/tmp/{FIX_VERSION}'
        )

        attachments = None
        with patch('os.path.exists') as mock_exists:
            mock_exists.return_value = False
            with patch('os.makedirs') as mock_os:
                attachments = Attachments(self._thread_manager, config)
                mock_os.assert_called_with('/tmp/' + Configuration().replacements.replace('{FIX_VERSION}'))

        self._thread_manager.append(attachments)

        with patch('pycurl.Curl') as mock_curl:
            with patch('pycurl.Curl.setopt') as mock_setopt:
                with patch('pycurl.Curl.perform') as mock_perform:
                    with patch('pycurl.Curl.close') as mock_close:
                        Curl = namedtuple('Curl', 'URL WRITEDATA setopt perform close getinfo')
                        mock_curl.return_value = Curl(
                            URL=None,
                            WRITEDATA=None,
                            setopt=mock_setopt,
                            perform=mock_perform,
                            close=mock_close,
                            getinfo=lambda x: 200
                        )
                        with self.assertRaises(InvalidCallbackError):
                            self._thread_manager.execute()
                        self.assertIsInstance(attachments.failure, InvalidCallbackError)
                        mock_setopt.assert_not_called()
                        mock_perform.assert_not_called()
                        mock_close.assert_not_called()
                        mock_open.assert_not_called()
示例#11
0
 def test_jira_attachments(self, mock_load, mock_search, mock_jira_client):
     data = DataProviders._test_data_for_attachments()
     mock_jira_client.return_value = None
     mock_search.return_value = data
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = 'jira'
             manager = ProjectManager()
             self.assertIsInstance(manager.client.client, JIRA)
             attachments = manager.search_issues(
                 search_query='assignee = "bob123"',
                 max_results=2,
                 fields=['attachments'])
示例#12
0
    def test_execute_retries_observers_on_error(self, mock_load, mock_jira_client):
        mock_jira_client.return_value = None
        with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager:
            with patch('pyccata.core.configuration.Configuration._configuration', new_callable=PropertyMock) as mock_config:
                mock_config.return_value = DataProviders._get_config_for_test()
                mock_manager.return_value = 'jira'

                mock_broken = BrokenConnectionFilter('assignee = "Bob"')
                mock_filter = Filter('assignee = "Bob"')

                manager = ThreadManager()
                manager.append(mock_broken)
                manager.append(mock_filter)
                mock_filter.projectmanager._client._client = DataProviders._get_client()

                self.assertEquals(1, len(manager))
                self.assertEquals(1, len(manager[0]._observers))
                manager.start()
示例#13
0
 def test_run_raises_exception_if_query_fails(self, mock_load,
                                              mock_jira_client):
     mock_jira_client.return_value = DataProviders._get_client()
     mock_jira_client.search_issues.side_effect = InvalidQueryError(
         'The specified query is invalid')
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = 'jira'
             mock_filter = Filter('iamnotavalidquery',
                                  namespace='pyccata.core')
             mock_filter.projectmanager = ProjectManager()
             mock_filter.start()
             self.assertTrue(mock_filter.failed)
             self.assertIsInstance(mock_filter.failure, InvalidQueryError)
示例#14
0
 def test_section_abstract_reads_abstract_from_file(self):
     Configuration._instance = DataProviders._get_config_for_test()
     Config = namedtuple('Config', 'title, abstract level structure')
     config = Config(title='hello world',
                     abstract='section_test_text',
                     level=0,
                     structure=None)
     section = Section(self._thread_manager, config)
     self.assertEquals('hello world', section._title)
     self.assertEquals(3, len(section._abstract._content))
示例#15
0
 def test_maxwidth(self, mock_load):
     with patch('pyccata.core.configuration.Configuration.reporting',
                new_callable=PropertyMock) as mock_reporting:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_reporting.return_value = 'docx'
             r = ReportManager()
             self.assertEquals(5.7, r.maxwidth)
示例#16
0
 def test_manager_loads_client_on_success(self, mock_load,
                                          mock_jira_client):
     key = 'jira'
     mock_jira_client.return_value = DataProviders._get_client()
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = key
             manager = ProjectManager()
             self.assertIsInstance(manager, ProjectManager)
             self.assertIsInstance(manager._client, Jira)
             self.assertTrue(ManagerInterface in manager.__implements__)
             self.assertTrue(
                 ManagerInterface in manager._client.__implements__)
             self.assertEquals('http://jira.local:8080',
                               manager.server.server_address)
示例#17
0
 def test_configuration_doesnt_assign_required_if_property_doesnt_exist(
         self, mock_config_list, mock_parser):
     mock_config = DataProviders._get_config_for_test()
     mock_config_list.return_value = [self._path]
     required_elements = [
         'manager', 'iamrequiredandexistinconfigbutdonothaveaproperty'
     ]
     self.tearDown()
     Configuration._configuration = mock_config
     Configuration._required_root_elements = required_elements
     config = Configuration(filename='config_no_property.json')
示例#18
0
 def test_run_marks_thread_as_complete_on_success(self, mock_load,
                                                  mock_jira_client):
     mock_jira_client.return_value = None
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = 'jira'
             mock_filter = Filter('assignee = "Bob"',
                                  namespace='pyccata.core')
             mock_filter.projectmanager = ProjectManager()
             mock_filter.projectmanager._client._client = DataProviders._get_client(
             )
             mock_filter.run()
             self.assertTrue(mock_filter.complete)
             self.assertEqual(
                 len(mock_filter.results),
                 len(DataProviders._test_data_for_search_results()))
示例#19
0
 def test_add_page_break(self, mock_document, mock_load):
     with patch('pyccata.core.configuration.Configuration.reporting',
                new_callable=PropertyMock) as mock_reporting:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_reporting.return_value = 'docx'
             r = ReportManager()
             r.add_page_break()
             mock_document.assert_called_with()
示例#20
0
 def test_add_run_with_no_style(self, mock_run, mock_load):
     with patch('pyccata.core.configuration.Configuration.reporting',
                new_callable=PropertyMock) as mock_reporting:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_reporting.return_value = 'docx'
             r = ReportManager()
             r.add_paragraph('hello world')
             r.add_run('This is a paragraph run')
             mock_run.assert_called_with('This is a paragraph run')
示例#21
0
 def test_add_paragraph(self, mock_document, mock_load, mock_locations):
     with patch('pyccata.core.configuration.Configuration.reporting',
                new_callable=PropertyMock) as mock_reporting:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_locations.return_value = [self._path]
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_reporting.return_value = 'docx'
             r = ReportManager()
             r.add_paragraph('hello world')
             mock_document.assert_called_with('hello world', style=None)
示例#22
0
    def test_configuration_raises_invalid_class_error_if_required_class_does_not_exist(
            self, data_key, data_driver, mock_config_list, mock_load):
        mock_config = DataProviders._get_config_for_test_with_invalid_classes()
        mock_load.return_value = None
        self.tearDown()

        mock_config_list.return_value = [self._path]
        Configuration._configuration = mock_config

        with self.assertRaises(InvalidClassError):
            config = Configuration(filename='config_sections.json')
            config.validate_config([data_key])
        mock_load.assert_called_once_with()
示例#23
0
 def test_manager_returns_search_result_list(self, mock_load,
                                             mock_jira_client):
     key = 'jira'
     mock_jira_client.return_value = None
     data = DataProviders._test_data_for_search_results()
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = key
             manager = ProjectManager()
             self.assertIsInstance(manager.client.client, JIRA)
             manager._client._client = DataProviders._get_client()
             self.assertEqual(
                 len(
                     manager.search_issues(
                         search_query='assignee = "bob123"',
                         max_results=2,
                         fields=[])),
                 len(DataProviders._test_data_for_search_results()))
示例#24
0
    def test_manager_raises_invalid_connection_exception_if_search_query_fails(
            self, mock_load, mock_search, mock_jira_client):
        key = 'jira'
        mock_jira_client.return_value = None
        mock_search.side_effect = JIRAError(status_code=500,
                                            text='Server Error')

        data = DataProviders._test_data_for_search_results()
        with patch('pyccata.core.configuration.Configuration.manager',
                   new_callable=PropertyMock) as mock_manager:
            with patch(
                    'pyccata.core.configuration.Configuration._configuration',
                    new_callable=PropertyMock) as mock_config:
                mock_config.return_value = DataProviders._get_config_for_test()
                mock_manager.return_value = key
                manager = ProjectManager()
                self.assertIsInstance(manager.client.client, JIRA)
                with self.assertRaisesRegexp(
                        InvalidConnectionError,
                        'Recieved HTTP/500 whilst establishing.*'):
                    manager.search_issues(search_query='assignee = "bob123"',
                                          max_results=2,
                                          fields=[])
示例#25
0
    def test_configuration_raises_requried_key_error_if_required_config_is_not_found(
            self, data_key, data_driver, mock_config_list, mock_load,
            mock_parser):
        mock_config = DataProviders._get_config_for_test_without_report(
            manager=data_driver, reporting=data_driver)
        mock_config_list.return_value = [self._path]
        Configuration._configuration = mock_config

        driver = data_driver if data_key != 'reporting' else 'report'
        with self.assertRaisesRegexp(RequiredKeyError,
                                     '.*\'<root>[./]?{0}\'.*'.format(driver)):
            config = Configuration(filename='config_missing.json')
            config.validate_config([data_key])
        mock_load.assert_called_once_with()
示例#26
0
    def test_csv_with_broken_file(self, mock_dataframe, mock_config_locations,
                                  mock_parse):
        self.tearDown()
        mock_config_locations.return_value = [self._path]
        mock_dataframe.side_effect = DataProviders.get_csv_results()
        with patch('pyccata.core.managers.clients.docx.Docx') as docx:
            docx.__implements__ = (ReportingInterface, )
            document = DocumentController('broken_csv.json')
            document.build()
            csvfiles = document._thread_manager.projectmanager._client._client
            self.assertIsInstance(csvfiles, CSVClient)
            self.assertEquals(len(csvfiles), 0)

            document.save('Test Document.docx')
示例#27
0
    def test_manager_loading_returns_true_if_required_is_valid(
            self, data_key, data_driver, mock_config_list, mock_load):
        mock_config = DataProviders._get_config_for_test(manager=data_driver,
                                                         reporting=data_driver)
        mock_load.return_value = None
        self.tearDown()

        mock_config_list.return_value = [self._path]
        Configuration._configuration = mock_config
        Configuration.NAMESPACE = 'tests.mocks'

        config = Configuration(filename='config_sections.json')
        config.validate_config([data_key])
        mock_load.assert_called_once_with()
        self.assertEquals(data_driver, getattr(config, data_key))
示例#28
0
 def test_render_calls_report_manager_add_methods(self, mock_paragraph):
     Configuration.report_text = 'tests/pyccata.core/data'
     config = DataProviders.get_paragraph_config_for_section()
     section = Section(self._thread_manager, config)
     self.assertEquals(4, len(section._structure))
     for item in section._structure:
         self.assertIsInstance(item, Paragraph)
     section.render(ReportManager())
     calls = [
         call('This is paragraph number 1'),
         call('This is paragraph number 3'),
         call('This is paragraph number 4'),
         call('This is paragraph number 5')
     ]
     mock_paragraph.assert_has_calls(calls)
示例#29
0
 def test_results_with_collation(self, collation, distinct, results,
                                 mock_load, mock_jira_client):
     mock_jira_client.return_value = None
     with patch('pyccata.core.configuration.Configuration.manager',
                new_callable=PropertyMock) as mock_manager:
         with patch(
                 'pyccata.core.configuration.Configuration._configuration',
                 new_callable=PropertyMock) as mock_config:
             mock_config.return_value = DataProviders._get_config_for_test()
             mock_manager.return_value = 'jira'
             mock_filter = Filter('assignee = "Bob"',
                                  collate=collation,
                                  distinct=distinct,
                                  namespace='pyccata.core')
             mock_filter.projectmanager = ProjectManager()
             mock_filter.projectmanager._client._client = DataProviders._get_client_for_collation(
             )
             mock_filter.run()
             self.assertTrue(mock_filter.complete)
             self.assertIsInstance(_today(), datetime)
             with patch('pyccata.core.collation._today',
                        new_callable=(lambda: datetime.strptime(
                            '2016-08-18', '%Y-%m-%d'))):
                 self.assertEqual(results, mock_filter.results)
示例#30
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)