# Path: elasticsearch_dsl/search.py
# class QueryProxy(object):
# class ProxyDescriptor(object):
# class AggsProxy(AggBase, DslBase):
# class Request(object):
# class Search(Request):
# class MultiSearch(Request):
#     def __init__(self, search, attr_name):
#     def __nonzero__(self):
#     def __call__(self, *args, **kwargs):
#     def __getattr__(self, attr_name):
#     def __setattr__(self, attr_name, value):
#     def __getstate__(self):
#     def __setstate__(self, state):
#     def __init__(self, name):
#     def __get__(self, instance, owner):
#     def __set__(self, instance, value):
#     def __init__(self, search):
#     def to_dict(self):
#     def __init__(self, using="default", index=None, doc_type=None, extra=None):
#     def __eq__(self, other):
#     def __copy__(self):
#     def params(self, **kwargs):
#     def index(self, *index):
#     def _resolve_field(self, path):
#     def _resolve_nested(self, hit, parent_class=None):
#     def _get_result(self, hit, parent_class=None):
#     def doc_type(self, *doc_type, **kwargs):
#     def using(self, client):
#     def extra(self, **kwargs):
#     def _clone(self):
#     def __init__(self, **kwargs):
#     def filter(self, *args, **kwargs):
#     def exclude(self, *args, **kwargs):
#     def __iter__(self):
#     def __getitem__(self, n):
#     def from_dict(cls, d):
#     def _clone(self):
#     def response_class(self, cls):
#     def update_from_dict(self, d):
#     def script_fields(self, **kwargs):
#     def source(self, fields=None, **kwargs):
#     def sort(self, *keys):
#     def highlight_options(self, **kwargs):
#     def highlight(self, *fields, **kwargs):
#     def suggest(self, name, text, **kwargs):
#     def to_dict(self, count=False, **kwargs):
#     def count(self):
#     def execute(self, ignore_cache=False):
#     def scan(self):
#     def delete(self):
#     def __init__(self, **kwargs):
#     def __getitem__(self, key):
#     def __iter__(self):
#     def _clone(self):
#     def add(self, search):
#     def to_dict(self):
#     def execute(self, ignore_cache=False, raise_on_error=True):


from elasticsearch_dsl.search import Q, Search
# 	http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing,
#  software distributed under the License is distributed on an
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#  KIND, either express or implied.  See the License for the
#  specific language governing permissions and limitations
#  under the License.



def test_count_all(data_client):
    s = Search(using=data_client).index("git")
    assert 53 == s.count()


def test_count_prefetch(data_client, mocker):
    mocker.spy(data_client, "count")

    search = Search(using=data_client).index("git")
    search.execute()
    assert search.count() == 53
    assert data_client.count.call_count == 0

    search._response.hits.total.relation = "gte"
    assert search.count() == 53
    assert data_client.count.call_count == 1


def test_count_filter(data_client):

# Path: elasticsearch_dsl/search.py
# class QueryProxy(object):
# class ProxyDescriptor(object):
# class AggsProxy(AggBase, DslBase):
# class Request(object):
# class Search(Request):
# class MultiSearch(Request):
#     def __init__(self, search, attr_name):
#     def __nonzero__(self):
#     def __call__(self, *args, **kwargs):
#     def __getattr__(self, attr_name):
#     def __setattr__(self, attr_name, value):
#     def __getstate__(self):
#     def __setstate__(self, state):
#     def __init__(self, name):
#     def __get__(self, instance, owner):
#     def __set__(self, instance, value):
#     def __init__(self, search):
#     def to_dict(self):
#     def __init__(self, using="default", index=None, doc_type=None, extra=None):
#     def __eq__(self, other):
#     def __copy__(self):
#     def params(self, **kwargs):
#     def index(self, *index):
#     def _resolve_field(self, path):
#     def _resolve_nested(self, hit, parent_class=None):
#     def _get_result(self, hit, parent_class=None):
#     def doc_type(self, *doc_type, **kwargs):
#     def using(self, client):
#     def extra(self, **kwargs):
#     def _clone(self):
#     def __init__(self, **kwargs):
#     def filter(self, *args, **kwargs):
#     def exclude(self, *args, **kwargs):
#     def __iter__(self):
#     def __getitem__(self, n):
#     def from_dict(cls, d):
#     def _clone(self):
#     def response_class(self, cls):
#     def update_from_dict(self, d):
#     def script_fields(self, **kwargs):
#     def source(self, fields=None, **kwargs):
#     def sort(self, *keys):
#     def highlight_options(self, **kwargs):
#     def highlight(self, *fields, **kwargs):
#     def suggest(self, name, text, **kwargs):
#     def to_dict(self, count=False, **kwargs):
#     def count(self):
#     def execute(self, ignore_cache=False):
#     def scan(self):
#     def delete(self):
#     def __init__(self, **kwargs):
#     def __getitem__(self, key):
#     def __iter__(self):
#     def _clone(self):
#     def add(self, search):
#     def to_dict(self):
#     def execute(self, ignore_cache=False, raise_on_error=True):


# Path: tests/test_integration/test_count.py
from elasticsearch_dsl.search import Q, Search

# 	http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing,
#  software distributed under the License is distributed on an
#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
#  KIND, either express or implied.  See the License for the
#  specific language governing permissions and limitations
#  under the License.



def test_count_all(data_client):
    s = Search(using=data_client).index("git")
    assert 53 == s.count()


def test_count_prefetch(data_client, mocker):
    mocker.spy(data_client, "count")

    search = Search(using=data_client).index("git")
    search.execute()
    assert search.count() == 53
    assert data_client.count.call_count == 0

    search._response.hits.total.relation = "gte"
    assert search.count() == 53
    assert data_client.count.call_count == 1


def test_count_filter(data_client):

    s = Search(using=data_client).index("git").filter(~Q("exists", field="parent_shas"))