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)
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)
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'])
def test_manager_raises_import_error_if_manager_class_does_not_exist( self, mock_load): key = 'agilemanager' Configuration.NAMESPACE = 'tests.mocks' with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager: mock_manager.return_value = key with self.assertRaises(ImportError): a = ProjectManager()
def test_manager_raises_invalid_module_error_if_manager_module_does_not_exist( self, mock_load): key = 'iwillneverbeamanager' with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager: mock_manager.return_value = key with self.assertRaisesRegexp( InvalidModuleError, '{0}.*{1}.*'.format(key, Configuration.NAMESPACE)): ProjectManager()
def test_manager_raises_invalid_class_error_if_manager_class_does_not_exist( self, mock_load): key = 'managermodule' Configuration.NAMESPACE = 'tests.mocks' with patch('pyccata.core.configuration.Configuration.manager', new_callable=PropertyMock) as mock_manager: mock_manager.return_value = key with self.assertRaisesRegexp( InvalidClassError, 'Managermodule .* {0}.*'.format(Configuration.NAMESPACE)): ProjectManager()
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()))
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=[])
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)
def __init__(self): if self._is_loaded: return super().__init__() self._managed_threads = 0 self._complete_threads = 0 Logger().debug('Loading project manager') self._projectmanager = ProjectManager() Logger().debug(str(self._projectmanager.threadmanager)) self._projectmanager.threadmanager = self self._querymanager = QueryManager() self._configuration = Configuration() self._failed_threads = [] self._pool = [] self._complete = False self._is_loaded = True
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)
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)
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()))
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 .*')
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)