# Path: data_catalog/search.py
# class DataSetSearchResource(DataCatalogResource):
# class IndexConnectionError(Exception):
# class DataSetSearch(DataCatalogModel):
#     def __init__(self):
#     def get(self):
#     def __init__(self):
#     def search(self, query, org_uuid_list, dataset_filtering, is_admin):
#     def _extract_metadata(es_query_result):
#     def get_params_from_request_args(args):
#     SEARCH_ERROR_MESSAGE = 'Searching in the index failed'
#     INVALID_QUERY_ERROR_MESSAGE = SEARCH_ERROR_MESSAGE + ': invalid query.'
#     NO_CONNECTION_ERROR_MESSAGE = SEARCH_ERROR_MESSAGE + ': failed to connect to ElasticSearch.'
# 
# Path: tests/base_test.py
# class DataCatalogTestCase(unittest.TestCase):
#     def setUp(self):
#         setup_fake_env()
#         self._config = DCConfig()
# 
#         self.app = data_catalog.app._create_app(self._config)
#         self.app.config['TESTING'] = True
#         self.client = self.app.test_client()
# 
#         self.mocked_authenticate = disable_authentication(self.client)
# 
#     def tearDown(self):
#         clean_fake_env()


import json
import unittest
import flask
from elasticsearch.exceptions import RequestError, ConnectionError
from mock import patch, MagicMock
from data_catalog.search import DataSetSearch, InvalidQueryError, IndexConnectionError
from tests.base_test import DataCatalogTestCase
    def setUp(self):
        super(SearchTests, self).setUp()
        self.fake_org_id = 'orgId001'
        self.test_search_result = {'whateverField': 'something'}
        self.test_total_hits = 666
        self.test_id = 13
        self.test_es_search_results = {
            'hits': {
                'hits': [
                    {
                        '_source': self.test_search_result,
                        '_id': self.test_id
                    }
                ],
                'total': self.test_total_hits
            },
            'aggregations': {
                'categories': {
                    'buckets': [
                        {
                            'key': 'health'
                        },
                        {
                            'key': 'science'
                        }
                    ]
                },
                'formats': {
                    'buckets': [
                        {

# Path: data_catalog/search.py
# class DataSetSearchResource(DataCatalogResource):
# class IndexConnectionError(Exception):
# class DataSetSearch(DataCatalogModel):
#     def __init__(self):
#     def get(self):
#     def __init__(self):
#     def search(self, query, org_uuid_list, dataset_filtering, is_admin):
#     def _extract_metadata(es_query_result):
#     def get_params_from_request_args(args):
#     SEARCH_ERROR_MESSAGE = 'Searching in the index failed'
#     INVALID_QUERY_ERROR_MESSAGE = SEARCH_ERROR_MESSAGE + ': invalid query.'
#     NO_CONNECTION_ERROR_MESSAGE = SEARCH_ERROR_MESSAGE + ': failed to connect to ElasticSearch.'
# 
# Path: tests/base_test.py
# class DataCatalogTestCase(unittest.TestCase):
#     def setUp(self):
#         setup_fake_env()
#         self._config = DCConfig()
# 
#         self.app = data_catalog.app._create_app(self._config)
#         self.app.config['TESTING'] = True
#         self.client = self.app.test_client()
# 
#         self.mocked_authenticate = disable_authentication(self.client)
# 
#     def tearDown(self):
#         clean_fake_env()


# Path: tests/test_search.py
import json
import unittest
import flask
from elasticsearch.exceptions import RequestError, ConnectionError
from mock import patch, MagicMock
from data_catalog.search import DataSetSearch, InvalidQueryError, IndexConnectionError
from tests.base_test import DataCatalogTestCase

    def setUp(self):
        super(SearchTests, self).setUp()
        self.fake_org_id = 'orgId001'
        self.test_search_result = {'whateverField': 'something'}
        self.test_total_hits = 666
        self.test_id = 13
        self.test_es_search_results = {
            'hits': {
                'hits': [
                    {
                        '_source': self.test_search_result,
                        '_id': self.test_id
                    }
                ],
                'total': self.test_total_hits
            },
            'aggregations': {
                'categories': {
                    'buckets': [
                        {
                            'key': 'health'
                        },
                        {
                            'key': 'science'
                        }
                    ]
                },
                'formats': {
                    'buckets': [
                        {

                            'key': 'csv'