<s> from __future__ import unicode_literals <EOL> import httpretty <EOL> import json <EOL> from pyeqs import QuerySet , Filter <EOL> from pyeqs . dsl import Aggregations , QueryString , ScriptScore , Sort , Term <EOL> from tests . helpers import homogeneous <EOL> def test_create_queryset ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> results = { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_query_string ( ) : <EOL> """<STR_LIT>""" <EOL> q = QueryString ( "<STR_LIT:foo>" ) <EOL> t = QuerySet ( "<STR_LIT>" , query = q ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT:foo>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_filter ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> t . filter ( Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_filters ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> t . filter ( Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> t . filter ( Term ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } , <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_filter_block ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> f = Filter ( "<STR_LIT>" ) . filter ( Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> t . filter ( f ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_sorting ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = Sort ( "<STR_LIT>" , order = "<STR_LIT>" ) <EOL> t . order_by ( s ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { } <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_multiple_sorting ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = Sort ( "<STR_LIT>" , order = "<STR_LIT>" ) <EOL> t . order_by ( s ) <EOL> ss = Sort ( "<STR_LIT>" , order = "<STR_LIT>" ) <EOL> t . order_by ( ss ) <EOL> results = { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_scoring ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = ScriptScore ( "<STR_LIT>" ) <EOL> t . score ( s ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : "<STR_LIT:replace>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_scoring_min_score_track_score ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = ScriptScore ( "<STR_LIT>" ) <EOL> t . score ( s , min_score = <NUM_LIT:0> , track_scores = True ) <EOL> results = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : "<STR_LIT:replace>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_multiple_scoring ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = ScriptScore ( "<STR_LIT>" ) <EOL> t . score ( s ) <EOL> boost = { <EOL> "<STR_LIT>" : "<STR_LIT:3>" , <EOL> "<STR_LIT>" : Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) <EOL> } <EOL> t . score ( boost ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:3>" , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT:replace>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_scoring_and_filtering ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = ScriptScore ( "<STR_LIT>" ) <EOL> t . score ( s ) <EOL> t . filter ( Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT:replace>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_scoring_and_filtering_from_object ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> s = ScriptScore ( "<STR_LIT>" ) <EOL> t . score ( s ) <EOL> f = Filter ( "<STR_LIT>" ) . filter ( Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> t . filter ( f ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT:replace>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_filters_and_scoring ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> t . filter ( Term ( "<STR_LIT:foo>" , "<STR_LIT:bar>" ) ) <EOL> s = ScriptScore ( "<STR_LIT>" ) <EOL> t . score ( s ) <EOL> t . filter ( Term ( "<STR_LIT>" , "<STR_LIT>" ) ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } <EOL> } , <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> ] , <EOL> "<STR_LIT>" : "<STR_LIT:replace>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_only_block ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> t . only ( "<STR_LIT>" ) <EOL> results = { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { } } , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_queryset_count ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> t . count ( ) . should . equal ( None ) <EOL> def test_queryset_max_score ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> t . max_score ( ) . should . equal ( None ) <EOL> def test_queryset_string ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" , query = "<STR_LIT:foo>" ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT:foo>" <EOL> } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> def test_create_queryset_with_aggregation ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" ) <EOL> a = Aggregations ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> t . aggregate ( a ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> a1 = Aggregations ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , size = <NUM_LIT:1> ) <EOL> t . aggregate ( a1 ) <EOL> results = { <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { } <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } , <EOL> "<STR_LIT>" : { "<STR_LIT>" : { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } , <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT:size>" : <NUM_LIT:1> <EOL> } } <EOL> } <EOL> } <EOL> homogeneous ( t . _query , results ) <EOL> @ httpretty . activate <EOL> def test_queryset_getitem ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT:localhost>" , index = "<STR_LIT:bar>" ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> results = t [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> len ( results ) . should . equal ( <NUM_LIT:1> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:1> ) <EOL> @ httpretty . activate <EOL> def test_queryset_getitem_with_wrapper ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT:localhost>" , index = "<STR_LIT:bar>" ) <EOL> wrapper = lambda y : list ( map ( lambda x : x [ '<STR_LIT>' ] , y ) ) <EOL> t . wrappers ( wrapper ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> results = t [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> len ( results ) . should . equal ( <NUM_LIT:1> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:1> ) <EOL> t . max_score ( ) . should . equal ( <NUM_LIT:10> ) <EOL> int ( results [ <NUM_LIT:0> ] ) . should . equal ( <NUM_LIT:1> ) <EOL> @ httpretty . activate <EOL> def test_queryset_getitem_multiple ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT:localhost>" , index = "<STR_LIT:bar>" ) <EOL> wrapper = lambda y : list ( map ( lambda x : x [ '<STR_LIT>' ] , y ) ) <EOL> t . wrappers ( wrapper ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> results = t [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> len ( results ) . should . equal ( <NUM_LIT:1> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:1> ) <EOL> results = t [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> len ( results ) . should . equal ( <NUM_LIT:1> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:1> ) <EOL> @ httpretty . activate <EOL> def test_queryset_iteration ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" , index = "<STR_LIT:bar>" ) <EOL> wrapper = lambda y : list ( map ( lambda x : x [ '<STR_LIT>' ] , y ) ) <EOL> t . wrappers ( wrapper ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> results = [ ] <EOL> for result in t : <EOL> results . append ( result ) <EOL> len ( results ) . should . equal ( <NUM_LIT:1> ) <EOL> len ( t ) . should . equal ( <NUM_LIT:1> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:1> ) <EOL> @ httpretty . activate <EOL> def test_queryset_iteration_with_no_results ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" , index = "<STR_LIT:bar>" ) <EOL> wrapper = lambda y : list ( map ( lambda x : x [ '<STR_LIT>' ] , y ) ) <EOL> t . wrappers ( wrapper ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : [ ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> results = [ ] <EOL> for result in t : <EOL> results . append ( result ) <EOL> len ( results ) . should . equal ( <NUM_LIT:0> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:0> ) <EOL> @ httpretty . activate <EOL> def test_queryset_iteration_with_multiple_cache_fetches ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT>" , index = "<STR_LIT:bar>" ) <EOL> wrapper = lambda y : list ( map ( lambda x : x [ '<STR_LIT>' ] , y ) ) <EOL> t . wrappers ( wrapper ) <EOL> t . _per_request = <NUM_LIT:2> <EOL> first_response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } , <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:2>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> second_response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:3> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:3>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> responses = [ <EOL> httpretty . Response ( body = json . dumps ( first_response ) , content_type = "<STR_LIT:application/json>" ) , <EOL> httpretty . Response ( body = json . dumps ( second_response ) , content_type = "<STR_LIT:application/json>" ) , <EOL> ] ) <EOL> results = [ ] <EOL> for result in t : <EOL> results . append ( result ) <EOL> len ( results ) . should . equal ( <NUM_LIT:3> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:3> ) <EOL> results [ <NUM_LIT:0> ] . should . equal ( "<STR_LIT:1>" ) <EOL> results [ <NUM_LIT:1> ] . should . equal ( "<STR_LIT:2>" ) <EOL> results [ <NUM_LIT:2> ] . should . equal ( "<STR_LIT:3>" ) <EOL> @ httpretty . activate <EOL> def test_queryset_getitem_with_post_query_action ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT:localhost>" , index = "<STR_LIT:bar>" ) <EOL> global my_global_var <EOL> my_global_var = <NUM_LIT:1> <EOL> def action ( self , results , start , stop ) : <EOL> global my_global_var <EOL> my_global_var += <NUM_LIT:1> <EOL> t . post_query_actions ( action ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:5> , <EOL> "<STR_LIT>" : <NUM_LIT:0> <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { <EOL> "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] <EOL> } <EOL> ] <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> results = t [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> len ( results ) . should . equal ( <NUM_LIT:1> ) <EOL> t . count ( ) . should . equal ( <NUM_LIT:1> ) <EOL> results [ <NUM_LIT:0> ] [ '<STR_LIT>' ] . should . equal ( '<STR_LIT:1>' ) <EOL> my_global_var . should . equal ( <NUM_LIT:2> ) <EOL> @ httpretty . activate <EOL> def test_queryset_aggregations ( ) : <EOL> """<STR_LIT>""" <EOL> t = QuerySet ( "<STR_LIT:localhost>" , index = "<STR_LIT:bar>" ) <EOL> a = Aggregations ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> t . aggregate ( a ) <EOL> response = { <EOL> "<STR_LIT>" : <NUM_LIT:12> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : <NUM_LIT:1> , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : [ <EOL> { "<STR_LIT>" : "<STR_LIT:bar>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT:1>" , <EOL> "<STR_LIT>" : <NUM_LIT:10> , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT:foo>" : "<STR_LIT:bar>" <EOL> } , <EOL> "<STR_LIT>" : [ <EOL> <NUM_LIT> <EOL> ] } <EOL> ] <EOL> } , <EOL> "<STR_LIT>" : { <EOL> "<STR_LIT>" : { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } <EOL> } <EOL> } <EOL> httpretty . register_uri ( httpretty . GET , "<STR_LIT>" , <EOL> body = json . dumps ( response ) , <EOL> content_type = "<STR_LIT:application/json>" ) <EOL> t [ <NUM_LIT:0> : <NUM_LIT:1> ] <EOL> t . aggregations ( ) . should . have . key ( "<STR_LIT>" ) . being . equal ( { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" } } ) </s>
