Esempio n. 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)
Esempio n. 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))
Esempio n. 3
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()
Esempio n. 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()
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
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()
Esempio n. 8
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)
Esempio n. 9
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)
Esempio n. 10
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()))
Esempio n. 11
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()))