def test_search_with_one_user_result(self, mock_search: MagicMock) -> None: mock_results = MagicMock() mock_results.hits.total = 1 mock_results.__iter__.return_value = [Response(result=vars(self.mock_result4))] mock_search.return_value = mock_results expected = SearchResult(total_results=1, results=[User(full_name='First Last', first_name='First', last_name='Last', team_name='Test team', email='*****@*****.**', github_username='******', manager_email='*****@*****.**', is_active=True, employee_type='FTE')]) resp = self.es_proxy.fetch_user_search_results(query_term='test_query_term', index='user_search_index') self.assertEquals(resp.total_results, expected.total_results, "search result is not of length 1") self.assertIsInstance(resp.results[0], User, "Search result received is not of 'Table' type!") self.assertDictEqual(vars(resp.results[0]), vars(expected.results[0]), "Search Result doesn't match with expected result!")
def _delete_document_helper(self, data: List[str], index: str) -> str: # fetch indices that use our chosen alias indices = self._fetch_old_index(index) # set the document type type = User.get_type() if index is USER_INDEX else Table.get_type() for i in indices: # build a list of elasticsearch actions for bulk deletion actions = self._build_delete_actions(data=data, index_key=i, type=type) # bulk delete documents in index self._bulk_helper(actions) return index