def test_table_renders_filter_results_from_cell_query_continues_if_filter_errors( self, mock_heading, mock_table): self.tearDown() Config = namedtuple('Config', 'rows columns style') with patch('pyccata.core.filter.Filter.results', new_callable=PropertyMock) as mock_results: ResultsList = namedtuple('ResultsList', 'total results') Result = namedtuple('Result', 'key release_text business_representative') mock_results.return_value = ResultsList( total=1, results=[ Result(key='testproj-123', release_text='I am test text', business_representative='Bob Smith') ]) Filter = namedtuple('Filter', 'max_results namespace') rows = Filter(max_results=5, namespace='pyccata.core') columns = ['Name', 'Description'] config = Config(rows=[['Data', rows]], columns=columns, style='Light heading 1') table = Table(self._thread_manager, config) table.title = 'Test Title' document = ReportManager() table.render(document) self.assertEquals(1, mock_table.call_count) self.assertEquals(1, mock_heading.call_count) mock_heading.assert_called_with('Test Title', 3)
def test_run_completes_if_filter_fails(self): mock_filter = Filter('bob', max_results=5, fields=None, namespace='pyccata.core') mock_filter._failure = InvalidQueryError('query is wrong') Config = namedtuple('Config', 'rows columns style') config = Config(rows=[['My search', mock_filter]], columns=['Test column', 'Test Results'], style=None) table = Table(self._thread_manager, config) table.run() self.assertTrue(table._complete)
def test_run_completes_if_filter_delays_in_completing(self): mock_filter = Filter('bob', max_results=5, fields=None, namespace='pyccata.core') Config = namedtuple('Config', 'rows columns style') config = Config(rows=[['My search', mock_filter]], columns=['Test column', 'Test Results'], style=None) with patch('pyccata.core.threading.Threadable.complete', new_callable=PropertyMock) as mock_thread: table = Table(self._thread_manager, config) mock_thread.side_effect = [False, False, True] table.run() self.assertTrue(table._complete)
def test_run_creates_table(self, mock_manager): Config = namedtuple('Config', 'rows columns style') rows = [] for i in range(6): rows.append( ['Row ' + str((i + 1)), 'Test description ' + str((i + 1))]) columns = ['Name', 'Description'] config = Config(rows=rows, columns=columns, style='Light heading 1') table = Table(self._thread_manager, config) self._thread_manager.execute() table.render(self._report_manager) calls = [call(headings=columns, data=rows, style='Light heading 1')] mock_manager.assert_has_calls(calls)
def test_table_doesnt_render_with_empty_filter_results( self, mock_heading, mock_table): self.tearDown() Config = namedtuple('Config', 'rows columns style') Filter = namedtuple('Filter', 'query max_results namespace') rows = Filter(query='project=mssportal', max_results=5, namespace='pyccata.core') columns = ['Name', 'Description'] config = Config(rows=rows, columns=columns, style='Light heading 1') table = Table(self._thread_manager, config) document = ReportManager() table.render(document) mock_table.assert_not_called() mock_heading.assert_not_called()
def test_create_table_manages_exception_if_filter_cannot_be_created( self, mock_manager): Config = namedtuple('Config', 'rows columns style') Filter = namedtuple('SubFilter', 'search_for bob') rows = Filter(search_for='project=mssportal', bob='fish') columns = ['Name', 'Description'] config = Config(rows=rows, columns=columns, style='Light heading 1') table = Table(self._thread_manager, config)
def test_table_renders_filter_results_multi_results_without_combine( self, mock_heading, mock_table): self.tearDown() Config = namedtuple('Config', 'rows columns style') with patch('pyccata.core.filter.Filter.results', new_callable=PropertyMock) as mock_results: results_set_one = ResultList(name='test results') result_issue = Issue() result_issue.description = 'This is a test item' results_set_one.append(result_issue) results_set_two = ResultList(name='another set of tests') another_result_issue = Issue() another_result_issue.description = 'This is a test item' results_set_two.append(another_result_issue) multi_results = MultiResultList() multi_results.combine = False multi_results.append(results_set_one) multi_results.append(results_set_two) mock_results.return_value = multi_results Filter = namedtuple('Filter', 'query max_results namespace') rows = Filter(query='project=mssportal', max_results=5, namespace='pyccata.core') columns = ['Name', 'Description'] config = Config(rows=rows, columns=columns, style='Light heading 1') table = Table(self._thread_manager, config) document = ReportManager() table.render(document) self.assertEquals(2, mock_table.call_count) self.assertEquals(2, mock_heading.call_count)