def test_get_with_indices(self, mocked_es): mocked_connection = mock.Mock() mocked_es.Elasticsearch.return_value = mocked_connection # Test default indices. self.api.post( query='{}' ) mocked_connection.search.assert_called_with( body={}, index=[self.api.config.elasticsearch.elasticsearch_index], doc_type=self.api.config.elasticsearch.elasticsearch_doctype ) # Test all indices. self.api.post( query='{}', indices=['ALL'] ) mocked_connection.search.assert_called_with( body={} ) # Test forcing indices. self.api.post( query='{}', indices=['socorro_201801', 'socorro_200047', 'not_an_index'] ) mocked_connection.search.assert_called_with( body={}, index=['socorro_201801', 'socorro_200047', 'not_an_index'], doc_type=self.api.config.elasticsearch.elasticsearch_doctype ) # Test default indices with an index schema based on dates. index_schema = 'socorro_%Y%W' config = self.get_base_config(es_index=index_schema) api = Query(config=config) now = datetimeutil.utc_now() last_week = now - datetime.timedelta(days=7) indices = api.generate_list_of_indexes(last_week, now) api.post( query='{}' ) mocked_connection.search.assert_called_with( body={}, index=indices, doc_type=api.config.elasticsearch.elasticsearch_doctype )
def test_get_with_indices(self, mocked_es): mocked_connection = mock.Mock() mocked_es.Elasticsearch.return_value = mocked_connection # Test indices with dates (the test configuration includes dates). self.api.get(query={"query": {}}) now = utc_now() last_week = now - datetime.timedelta(days=7) indices = generate_list_of_indexes( last_week, now, self.api.context.get_index_template()) mocked_connection.search.assert_called_with( body='{"query": {}}', index=indices, doc_type=self.es_context.get_doctype(), ) # Test all indices. self.api.get(query={"query": {}}, indices=["ALL"]) mocked_connection.search.assert_called_with(body='{"query": {}}') # Test forcing indices. self.api.get( query={"query": {}}, indices=["socorro_201801", "socorro_200047", "not_an_index"], ) mocked_connection.search.assert_called_with( body='{"query": {}}', index=["socorro_201801", "socorro_200047", "not_an_index"], doc_type=self.es_context.get_doctype(), ) # Test default indices with an index schema based on dates. index_schema = "testsocorro" config = self.get_base_config(cls=Query, es_index=index_schema) api = Query(config=config) api.get(query={"query": {}}) mocked_connection.search.assert_called_with( body='{"query": {}}', index=["testsocorro"], doc_type=api.context.get_doctype(), )
def __init__(self, *args, **kwargs): super(IntegrationTestQuery, self).__init__(*args, **kwargs) self.api = Query(config=self.config)
def setup_method(self): super().setup_method() config = self.get_base_config(cls=Query) self.api = Query(config=config)
def setup_method(self, method): super(IntegrationTestQuery, self).setup_method(method) self.api = Query(config=self.config)