def test_filter2repos_get_types(self): repos = es_utils.filter2repos({}) self.assertIsNone(repos) types = es_utils.get_doc_types(repos) self.assertEqual(es_utils.REPOS, types) repos = es_utils.filter2repos({"query": {"repo": "ingest,published"}}) self.assertEqual("ingest,published", repos) types = es_utils.get_doc_types(repos) self.assertEqual(["ingest", "published"], types)
def test_filter2repos_get_types(self): repos = es_utils.filter2repos({}) self.assertIsNone(repos) types = es_utils.get_doc_types(repos) self.assertEqual(es_utils.REPOS, types) repos = es_utils.filter2repos({'query': {'repo': 'ingest,published'}}) self.assertEqual('ingest,published', repos) types = es_utils.get_doc_types(repos) self.assertEqual(['ingest', 'published'], types)
def publish_report(user_id, search_data): """Create report for a search and send it by email""" search_filter = json.loads(search_data['filter']) query = es_utils.filter2query(search_filter, user_id=user_id) repos = es_utils.filter2repos(search_filter) types = es_utils.get_doc_types(repos) found = superdesk.app.data.elastic.es.search( body=query, index=es_utils.get_index(types), doc_type=types) docs = es_utils.get_docs(found) send_report_email(user_id, search_data, docs)
def _get_types(self, req): """Get document types for the given query.""" args = getattr(req, "args", {}) repos = args.get("repo") return es_utils.get_doc_types(repos, self.repos)