Example #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)
Example #2
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))
Example #3
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)
Example #4
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))
Example #5
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')
Example #6
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()
Example #7
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)
Example #8
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')
Example #9
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)
Example #10
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()
Example #11
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()
Example #12
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))
Example #13
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)
Example #14
0
 def test_configuration_calls_validation_once_config_is_loaded(
         self, data_key, data_driver, mock_config_list, mock_load):
     mock_config = DataProviders._get_config_for_test()
     mock_config_list.return_value = [self._path]
     mock_load.return_value = None
     self.tearDown()
     Configuration._configuration = mock_config
     required_elements = [data_key]
     config = Configuration(filename='config_sections.json')
     mock_load.assert_called_once_with()
     with patch('pyccata.core.configuration.Configuration.{0}'.format(
             data_key),
                new_callable=PropertyMock) as mock_manager:
         mock_manager.return_value = object()
         self.assertTrue(config.validate_config(required_elements))
         mock_manager.assert_called_with(data_driver)
Example #15
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)
Example #16
0
    def test_add_picture(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_picture('/path/to/image.png')
                mock_document.assert_called_with('/path/to/image.png',
                                                 width=5212080)

                r.add_picture('/another/path/to/image.png', width=75)
                mock_document.assert_called_with('/another/path/to/image.png',
                                                 width=68580000)
Example #17
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'])
Example #18
0
 def test_results_with_collation_method_that_doesnt_exist(
         self, mock_load, mock_jira_client):
     collation = 'iamamethodwhichwillneverexist'
     distinct = False
     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'
             with self.assertRaises(InvalidModuleError):
                 mock_filter = Filter('assignee = "Bob"',
                                      collate=collation,
                                      distinct=distinct,
                                      namespace='pyccata.core')
Example #19
0
    def test_execute_adds_to_failures_when_all_observers_fail(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 = BrokenConnectionFilter('assignee = "Bob"')

                manager = ThreadManager()
                manager.append(mock_broken)
                manager.append(mock_filter)

                self.assertEquals(1, len(manager))
                self.assertEquals(1, len(manager[0]._observers))
                manager.start()
                self.assertEquals(1, len(manager._failed_threads))
Example #20
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)
Example #21
0
    def test_add_table(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'
                mock_document.return_value = self._document.add_table(rows=1,
                                                                      cols=3)
                r = ReportManager()
                headers = ['Test header', 'Another Test Header', 'Value']

                data = [[1, 2, 3], [4, 5, 9], [3, 9., 12]]
                r.add_table(headings=headers, data=data, style='Test Style')
                mock_document.assert_called_with(rows=1,
                                                 cols=3,
                                                 style='Test Style')
Example #22
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)
Example #23
0
    def test_config_getattr_method(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.check = True
        required_elements = [data_key]
        config.validate_config(required_elements)
        mock_load.assert_called_once_with()
        self.assertTrue(config.check)
        with self.assertRaises(AttributeError):
            config.iamnothere
Example #24
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()))
Example #25
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()))
Example #26
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=[])
Example #27
0
    def test_manager_raises_exception_on_client_initialisation_failure(
            self, mock_load, mock_jira_client):
        key = 'jira'
        mock_jira_client.return_value = None
        mock_jira_client.side_effect = JIRAError(status_code=500,
                                                 text='something')
        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(
                    port='')
                mock_manager.return_value = key
                with self.assertRaises(InvalidConnectionError) as cm:
                    manager = ProjectManager()
                    v = manager.client.client

                e = cm.exception
                self.assertEqual(500, e._code)
                self.assertEqual('something', e._error)
                self.assertRegexpMatches(
                    str(e),
                    'Recieved HTTP\/\d+ whilst establishing connection to .*')
Example #28
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)